Page 1 of 1
Error messages after using custom tags
Posted: Thu Mar 29, 2007 8:29 pm
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
Re: Error messages after using custom tags
Posted: Thu Mar 29, 2007 9:02 pm
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:
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:
Regards,
D
Re: Error messages after using custom tags
Posted: Thu Mar 29, 2007 9:07 pm
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.
Re: Error messages after using custom tags
Posted: Thu Mar 29, 2007 9:48 pm
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?
Re: Error messages after using custom tags
Posted: Thu Mar 29, 2007 10:21 pm
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
Re: Error messages after using custom tags
Posted: Thu Mar 29, 2007 10:25 pm
by moltar
Great! Thank you very much for your in-depth replies. This is very helpfull!