How to use established db connection $dbinstance

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
Glenn

How to use established db connection $dbinstance

Post 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;
Piratos

Re: How to use established db connection $dbinstance

Post by Piratos »

You cannot use mysql functions directly because adodb lite or adodb is in use.

Take a module source as an example.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: How to use established db connection $dbinstance

Post 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>");
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Locked

Return to “CMSMS Core”