#34906 [NEW]: There is no way to get errno for a failed secondary connection attempt

From: Date: Tue, 18 Oct 2005 11:19:53 +0000
Subject: #34906 [NEW]: There is no way to get errno for a failed secondary connection attempt
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-86688@lists.php.net to get a copy of this message
From: feldgendler at mail dot ru Operating system: Debian GNU/Linux PHP version: 5.0.5 PHP Bug Type: MySQL related Bug description: There is no way to get errno for a failed secondary connection attempt Description: ------------ This is actually a bug in the well-defined and documented API, so there is no reproduce code here. After successfully establishing a connection, when an attempt to create another connection fails, there is no way to find out the errno. This is because mysql_errno() always uses an established link, either the one passed as the argument or the default one. There is just no way to find out why the second connection failed. // assume this one succeeds $first_connection = mysql_connect($host1, $u1, $p1); // at this point, $first_connection is the default link // assume this one fails $second_connection = mysql_connect($host2, $u2, $p2); // $second_connection is false, // $first_connection is still the default link echo mysql_errno(); // 0 is printed because there is no error // on $first_connection Before stamping "Bogus" on this bug, please note the following: 1. I have read the manual about mysql_errno() and mysql_connect(). Every word of it. Even more, I think that PHP currently behaves as documented. But it's just wrong because there is no way to find out why a connection has failed. 2. I have read other bug reports about mysql_errno(). They are actually about other issues, or they don't state this problem clearly enough, so I'm filing this bug report to make it clear what the problem is. 3. I have read the source code of the mysql extension. From the source, I've found out that the error code and message from a failed connection attempt is really stored in mysql_globals (connect_errno and connect_error), but mysql_errno() PHP function only returns MySG(connect_errno) when the function is invoked without arguments AND there is no default link. If there is a default link, and an attempt to establish a second one has failed, there isn't a way to have MySG(connect_errno) returned to the PHP program. It is not obvious how to fix this bug, because it isn't a deviation from the documented behavior, but rather an incompleteness of the API. Two of the possible approaches are proposed here: http://www.mail-archive.com/internals@lists.php.net/msg02524.html -- Edit bug report at http://bugs.php.net/?id=34906&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=34906&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=34906&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=34906&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=34906&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=34906&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=34906&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=34906&r=needscript Try newer version: http://bugs.php.net/fix.php?id=34906&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=34906&r=support Expected behavior: http://bugs.php.net/fix.php?id=34906&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=34906&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=34906&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=34906&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=34906&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=34906&r=dst IIS Stability: http://bugs.php.net/fix.php?id=34906&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=34906&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=34906&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=34906&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=34906&r=mysqlcfg

« previous php.bugs (#86688) next »