db-connections and destructors (bug?)

From: Date: Sun, 15 Jul 2001 00:23:00 +0000
Subject: db-connections and destructors (bug?)
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-784@lists.php.net to get a copy of this message
There seems to be some kind of bug with mysql-connections and the shutdown-function in php 4.0.5 (which is used by PEAR's destructor function). Apparently the connection is broken, although it is not clear how. I'm trying to do a management-system for database-objects where the changes made to the objects may be sent to the database at the end of script execution (thereby avoiding a lot of single "update..."-statements). The problem is that all queries at that time seems to abort the script without returning a Error-object. It appears as if the mysql_query() function just silently dies. Since there can be no output at script-execution end one must put debug info in the session. Given you have a $db-object this code can be used to test this: <code> session_start(); session_register('inScriptResult'); session_register('atEndResult'); session_register('inScriptDb'); session_register('atEndDb'); $GLOBALS['inScriptDb'] = $GLOBALS['db']->toString(); $GLOBALS['inScriptResult'] = $GLOBALS['db']->getOne('show tables'); function test() { $GLOBALS['atEndDb'] = $GLOBALS['db']->toString(); $GLOBALS['atEnd'] = $GLOBALS['db']->getOne('show tables'); } register_shutdown_function("test"); </code> The resulting session-string is: inScriptResult|s:10:"aTable";!atEndResult|inScriptDb|s:53:"db_mysql: (phptype=mysql, dbsyntax=mysql) [connected]";atEndDb|s:53:"db_mysql: (phptype=mysql, dbsyntax=mysql) [connected]"; Anyone else having this problem? And on another note, perhaps there should be a mention in the Db-documentation about the problems with mySql's use of existing connections? <code> $db1 = Db::connect("mysql://user:passw@localhost/db1"); $db2 = Db::connect("mysql://user:passw@localhost/db2"); </code> Because we're using the same username and the same password on the same box php will make $db2 take over $db1's connection. Thus calls to $db1 will most surely result in error as it's pointing to database 'db2'. More info can be found at http://www.php.net/manual/en/function.mysql-connect.php . A possible solution is: <code> $db1 = Db::connect("mysql://user:passw@localhost/db1"); $db2 = Db::connect("mysql://user:passw@127.0.0.1/db2"); </code> /erik hjortsberg

« previous php.pear.dev (#784) next »