Closing open PEAR database connections

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
future_man
Forum Newbie
Posts: 8
Joined: Wed Jun 25, 2003 6:08 pm

Closing open PEAR database connections

Post by future_man »

I'm having an issue when closing PEAR DB database connections which either didn't open or possibly having already closed.

I have a disconnect() function which looks like this:

Code: Select all

function disconnect()
{       
    if ($this->database_connection && !DB::isError($this->database_connection)) {
        $this->database_connection->disconnect();           
    }
}
It lives in the __destruct() function for a database class which has been extended.

It appears to work as intended most of the time, but one of the classes that extends it seems to be trying to close a connection that either doesn't exist or may have been already closed generating the following error in the log files:

Code: Select all

[Wed Feb 13 17:50:19 2008] [error] PHPWARN (suppressed; ErrorProcessor) - 192.168.130.136: mysql_close(): 1073 is not a valid MySQL-Link resource in /usr/local/php5/lib/php/DB/mysql.php at line 277
I'm trying to find the offending class and code, but is there something else I could be doing to check to make sure its a valid connection before trying to close it?

Any help would be much appreciated.

Thanks!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Closing open PEAR database connections

Post by Christopher »

Does PEAR DB have a method to check if there is a connection? If so use that to put and if() around the disconnect().
(#10850)
Post Reply