Check out the LimeSurvey source code on GitHub!

Reuse LimeSurveys DB connection

More
4 years 3 days ago - 4 years 3 days ago #92888 by pchristoph
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
Last Edit: 4 years 3 days ago by pchristoph.

Please Log in to join the conversation.

More
4 years 3 days ago #92895 by holch
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.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

More
4 years 3 days ago #92897 by helper
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);
The following user(s) said Thank You: pchristoph

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form