Reuse LimeSurveys DB connection

More
4 years 5 months ago - 4 years 5 months ago #92888 by pchristoph
pchristoph created the topic: Reuse LimeSurveys DB connection
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 5 months ago by pchristoph.

Please Log in to join the conversation.

More
4 years 5 months ago #92895 by holch
holch replied the topic: Reuse LimeSurveys DB connection
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 5 months ago #92897 by helper
helper replied the topic: Reuse LimeSurveys DB connection
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.

Did you already participate in our customer survey?

Don't miss your chance for great prices.

Please click here to participate:

Start now

Start now!

Just create your account and start using Limesurvey today.

Register now