php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41407 mysql_errno/mysql_error not working on connect failures when another connection
Submitted: 2007-05-16 07:51 UTC Modified: 2007-05-17 12:18 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:3 (100.0%)
From: david at ols dot es Assigned: georg (profile)
Status: Wont fix Package: MySQL related
PHP Version: 4.4.7 OS: any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: david at ols dot es
New email:
PHP Version: OS:

 

 [2007-05-16 07:51 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-05-17 12:18 UTC] georg@php.net
This change would break BC.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Sep 28 05:03:38 2021 UTC