Welcome, Guest
Username: Password: Remember me

TOPIC: Reuse LimeSurveys DB connection

Reuse LimeSurveys DB connection 1 year 2 months ago #92888

  • pchristoph
  • pchristoph's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 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
Last Edit: 1 year 2 months ago by pchristoph.
The administrator has disabled public write access.

Reuse LimeSurveys DB connection 1 year 2 months ago #92895

  • holch
  • holch's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 2447
  • Thank you received: 254
  • Karma: 94
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!
The administrator has disabled public write access.

Reuse LimeSurveys DB connection 1 year 2 months ago #92897

  • helper
  • helper's Avatar
  • OFFLINE
  • Expert Lime
  • Posts: 126
  • Thank you received: 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);
The administrator has disabled public write access.
The following user(s) said Thank You: pchristoph
Moderators: ITEd
Time to create page: 0.225 seconds
Donation Image