From: rahlentertainment at gmail dot com Operating system: Ubuntu 9.04 PHP version: 5.2.10 PHP Bug Type: Feature/Change Request Bug description: New Functions for Getting and Setting the Default Connection Handle
Description: ------------ When you open a database connection with mysql_connect(), the function returns a connection handle. Subsequent calls to mysql_query() assume the last connection if no connection handle is specified. Unfortunately, there doesn't seem to be any way to get this connection handle again, without calling mysql_connect() a second time with the original arguments. There should be a way to get the connection handle again, without calling mysql_connect(), using something like mysql_get_last_connection() or similar. Rational: Consider a large PHP application. The creators call mysql_connect() at the begining of their application, and, since they only use one database, they don't save the connection handle, and let PHP automatically use the last (and only) connection. Another developer comes along, and writes a plug-in for the main application. This plug-in requires a second database connection. When the plug-in calls mysql_connect() to connect to it's database, the rest of the original application breaks, because it's trying to use the plug-in's database connection, because it was the last one opened. Reproduce code: --------------- // Start of a plug-in. $OldDBH = mysql_get_last_connection(); // new function $NewDBH = mysql_connect(...); // some processing here... // Plug-in has finished it's work mysql_set_last_connection($OldDBH); // new function, tells php to use the specified connection handle as the default for subsequent mysql_query() calls which do not explicitly specify one. // Plugin returns control to main app // main app calls mysql_query() without specifying a dbh mysql_query(); // this works, because $OldDBH was set back as the default. -- Edit bug report at http://bugs.php.net/?id=49400&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=49400&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=49400&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=49400&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=49400&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=49400&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=49400&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=49400&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=49400&r=needscript Try newer version: http://bugs.php.net/fix.php?id=49400&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=49400&r=support Expected behavior: http://bugs.php.net/fix.php?id=49400&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=49400&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=49400&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=49400&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=49400&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=49400&r=dst IIS Stability: http://bugs.php.net/fix.php?id=49400&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=49400&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=49400&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=49400&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=49400&r=mysqlcfg