Error messages after using custom tags

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.
Post Reply
moltar
New Member
New Member
Posts: 7
Joined: Thu Jan 04, 2007 2:29 am

Error messages after using custom tags

Post by moltar »

I am getting crazy error messages after using custom user tags. The messages appear to be within the menu area, that is in place where the menu should be. The menu does not display at all and everything else after on that page gets cut off. Here are the error messages:

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Access denied for user 'username'@'localhost' (using password: NO) in /home/username/public_html/lib/adodb_lite/adodbSQL_drivers/mysql/mysql_driver.inc on line 174

Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/username/public_html/lib/adodb_lite/adodbSQL_drivers/mysql/mysql_driver.inc on line 174

Fatal error: Call to a member function on a non-object in /home/username/public_html/modules/MenuManager/action.default.php on line 90
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm

Re: Error messages after using custom tags

Post by Dee »

Is your custom tag creating/using a mysql connection?
It looks like CMS Made Simple lost connection.
When you need database access from your tag, it's best to use the existing ADOdb object:

Code: Select all

$db =& $gCms->GetDb();
When using a MySQL connection, make sure you close the connection by passing the resource ID returned by mysql_connect() to mysql_close():

Code: Select all

$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password');
- - database code - -
mysql_close($link);
A work around is to re-connect CMS Made Simple at the end of your (tag) code:

Code: Select all

adodb_connect();
Regards,
D
moltar
New Member
New Member
Posts: 7
Joined: Thu Jan 04, 2007 2:29 am

Re: Error messages after using custom tags

Post by moltar »

Yes, the tag does open a new MySQL connection. The things is I can't reuse the CMSMS's connection, because I am connecting to a different database. I will try you suggestion about closing the connection though. I think I understand what is going on. When I don't specify which connection to close, it just closes the connection that belongs to CMSMS.
moltar
New Member
New Member
Posts: 7
Joined: Thu Jan 04, 2007 2:29 am

Re: Error messages after using custom tags

Post by moltar »

Nice one Dee! Thanks! The workaround seemed to work.

I just thought of something. The second database I am connecting to through the tag uses the same username and password as the CMSMS uses. Is there a way to reuse the connection, but select a different database?
Dee
Power Poster
Power Poster
Posts: 1197
Joined: Sun Mar 19, 2006 8:46 pm

Re: Error messages after using custom tags

Post by Dee »

It's possible to use the same connection by changing database:

Code: Select all

global $gCms;
$conn =& $gCms->GetDb();
$conn->Execute('USE your_db');
... your (ADOdb) database code ...
$conn->Execute('USE cms');
You can also create a second connection:

Code: Select all

global $gCms;
$config =& $gCms->GetConfig();
$conn =& ADONewConnection('mysql');
$conn->PConnect($config['db_hostname'], $config['db_username'], $config['db_password'], 'your_db');
... your (ADOdb) database code ...
$conn->Close();
Regards,
D
moltar
New Member
New Member
Posts: 7
Joined: Thu Jan 04, 2007 2:29 am

Re: Error messages after using custom tags

Post by moltar »

Great! Thank you very much for your in-depth replies. This is very helpfull!
Post Reply

Return to “CMSMS Core”