How to us CMSMS db connection
Posted: Fri Jun 23, 2006 1:41 am
I know Wishy has said you can use the exisiting connection, but I can't figure it out. I know I'm compromising my security, but my solution below is all I can figure out. Any help is appreciated.
When i need to do a custom query to the database this is what I do. I've created a plugin in the plugins folder called function.dblink.php that looks like this:
Then I create a user-defined tag when needed that start like this:
What's the best way to do this?
When i need to do a custom query to the database this is what I do. I've created a plugin in the plugins folder called function.dblink.php that looks like this:
Code: Select all
function smarty_cms_function_dblink($params, &$smarty)
{
global $gCms;
$vars = &$gCms->variables;
//Setup the database connection
$dbhost = "XXX";
$dbusername = "XXX";
$dbuserpass = "XXX";
$default_dbname = "XXX";
$dblink = mysql_connect($dbhost, $dbusername, $dbuserpass);
if (!$dblink)
{
die('Could not connect: ' . mysql_error());
}
else
{
mysql_select_db($default_dbname);
$vars['dblink'] = $dblink;
}
}
Code: Select all
global $gCms;
$dblink = $gCms->variables['dblink'];
$query = "SELECT * FROM cms_content WHERE metatdata LIKE '%beef%'";
$result = mysql_query($query,$dblink);
and so on...