Page 1 of 1

How to use established db connection $dbinstance

Posted: Thu Apr 06, 2006 4:38 pm
by Glenn
If I am writing user tags that use a query is there a way to use the connection that is established by CMSMS, which I believe is $dbinstance?

Here's what I tried (not really expecting it to work--and it didn't) but you'll get the idea of what I'm trying to do. (I know how to get the parent id from the globals array, I'm just using that as a test scenario here):

Code: Select all

global $gCms, $dbinstance;
$alias = $gCms->variables['page'];


///Get the info for the current page
$query = "SELECT parent_id FROM cms_content WHERE content_alias = '$alias'";
$result = mysql_query($query,$dbinstance);
$content = mysql_fetch_assoc($result);
	
$parent_id = $content['parent_id'];

echo "Parent id: ".$parent_id;

Re: How to use established db connection $dbinstance

Posted: Thu Apr 06, 2006 4:41 pm
by Piratos
You cannot use mysql functions directly because adodb lite or adodb is in use.

Take a module source as an example.

Re: How to use established db connection $dbinstance

Posted: Thu Apr 06, 2006 9:09 pm
by calguy1000
I beleive you can do something like this (if your working with the same database that is).

Code: Select all

global $gCms;
$db = $gCms->GetDb();
$dbresult = $db->Execute( $query, "SELECT * FROM <TABLENAME>");