Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: Reuse LimeSurveys DB connection

Reuse LimeSurveys DB connection 1 Jahr 8 Monate her #92888

  • pchristoph
  • pchristophs Avatar
  • OFFLINE
  • Fresh Lemon
  • Beiträge: 15
  • Karma: 0
Hi,

I am using Version 2.00+ Build 130219 and want to run a php script using a table that resides on the limesurvey-db.
My idea was to include_once("/application/config/config.php") and the work with this as I did using 1.9x.

Obviously the config file changed and the db connection is handled differently now.

Unfortunately I am not a programmer but rather able to script a little php. How can I use the existing limesurvey db connection by referencing the key/values needed?

The way I did it in LS 1.9x
include_once("../limesurvey/config.php");
$link = mysql_connect($databaselocation, $databaseuser, $databasepass)
    or die("No DB-Connection possible: " . mysql_error());

Many thanks!
Christoph
Letzte Änderung: 1 Jahr 8 Monate her von pchristoph.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Reuse LimeSurveys DB connection 1 Jahr 8 Monate her #92895

  • holch
  • holchs Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 2852
  • Dank erhalten: 360
  • Karma: 125
You don't need to go throught the limesurvey config file. You can just connect to your database as you would with any other web application via PHP.
Have a look at the manual! It is a really valuable source for information. Here some helpful links:
Manual (EN) | Question Types | Question Attributes | Workarounds

If you found this answer helpful and it saved you some time please consider a donation to the project to keep Limesurvey going!
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Reuse LimeSurveys DB connection 1 Jahr 8 Monate her #92897

  • helper
  • helpers Avatar
  • OFFLINE
  • Expert Lime
  • Beiträge: 126
  • Dank erhalten: 18
  • Karma: 0
Your "connection" is readily available most anywhere. The following is an example that you can play with:
//count number of answers
		$query = "SELECT count(*) FROM {{survey_".intval($iSurveyID)."}}";
 
		$result = Yii::app()->db->createCommand($query)->queryAll();
 
		//$totalrecords = total number of answers
		foreach($result as $row) {
		    $totalrecords = reset($row);
		}
 
		echo("total records: ".$totalrecords);
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: pchristoph
Moderatoren: ITEd
Ladezeit der Seite: 0.211 Sekunden
Donation Image