From: david at ols dot es
Operating system: any
PHP version: 4.4.7
PHP Bug Type: MySQL related
Bug description: mysql_errno/mysql_error not working on connect failures when
another connection
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 bug report at http://bugs.php.net/?id=41407&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=41407&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=41407&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=41407&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=41407&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=41407&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=41407&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=41407&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=41407&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=41407&r=support
Expected behavior: http://bugs.php.net/fix.php?id=41407&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=41407&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=41407&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=41407&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41407&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=41407&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=41407&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=41407&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=41407&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=41407&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=41407&r=mysqlcfg