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...

