#41407 [Asn->WFx]: mysql_errno/mysql_error not working on connect failures when another connection

From: Date: Thu, 17 May 2007 12:18:22 +0000
Subject: #41407 [Asn->WFx]: mysql_errno/mysql_error not working on connect failures when another connection
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-112737@lists.php.net to get a copy of this message
ID: 41407 Updated by: georg@php.net Reported By: david at ols dot es -Status: Assigned +Status: Wont fix Bug Type: MySQL related Operating System: any PHP Version: 4.4.7 Assigned To: georg New Comment: This change would break BC. Previous Comments: ------------------------------------------------------------------------ [2007-05-16 07:51:36] david at ols dot es Description: ------------ mysql_errno/mysql_error return valid results on connection failures, but if you try to connect to a second server while the connection to the first one is opened, then they return null results, which is ok, as per doc, the error given is for the last opened connection and not for the last performed mysql operation. I've seen other "bugs" like this closed as bogus because the documentation says what it says but what's really bogus is the current mysql_error/errno implementation. This makes mysql_error/errno not only unuseful in that situations but also makes it behave differently from what it does in another laguages (where is always possible to retrieve error information on connect failures). To be able to catch this errors (as in any other language), mysql_error/errno should report the status of the last mysql operation when no link identifier is given and not report the result of the last operation on the last opened connection. This will be easy to implement by just storing error information when any mysql functions fails. Reproduce code: --------------- $host = "localhost"; $user = "bogus"; $pw = "foo"; $conn = mysql_connect($host, $user, $pw); echo "MySQL status: (". mysql_errno().": '".mysql_error()."')<BR>"; $host = "localhost"; $user = "user_ok"; $pw = "pass_ok"; $conn = mysql_connect($host, $user, $pw); echo "MySQL status: (". mysql_errno().": '".mysql_error()."')<BR>"; $host = "localhost"; $user = "bogus"; $pw = "foo"; $conn = mysql_connect($host, $user, $pw); echo "MySQL status: (". mysql_errno().": '".mysql_error()."')<BR>"; Expected result: ---------------- first connection failed, error reported ok second connection succed third connection failed, error reported ok Actual result: -------------- first connection failed, error reported ok second connection succed third connection failed, error not reported ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=41407&edit=1

« previous php.bugs (#112737) next »