|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24689 mysql_connect() doesn't set mysql_error() to false on valid connect
Submitted: 2003-07-17 06:08 UTC Modified: 2003-07-18 00:22 UTC
Avg. Score:3.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: moa_hunter at yahoo dot com Assigned:
Status: Wont fix Package: MySQL related
PHP Version: 4.3.2 OS: Linux from source, 2.4.21
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.
Block user comment
Status: Assign to:
Bug Type:
From: moa_hunter at yahoo dot com
New email:
PHP Version: OS:


 [2003-07-17 06:08 UTC] moa_hunter at yahoo dot com
If an error is created by a mysql query, then you try to open a new database connection, then call mysql_error(), mysql_error() returns the error from the failed query, not false because the connection was valid.

Having searched through the bug reports, esp 2051, 10291, and 22651, it seems like mysql_error() should be false from version 4.0.6 onwards.

Reproduce code:
$connect_id = mysql_connect("localhost","auser","pass");
$query = "INSERT INTO  VALUES('0012', 'Mike's place', 'false')";
  $con_id_2 = mysql_connect("localhost", "someuser", "apass");
    //abort with error
  } else
    //code to write error to database

//I know one should check if mysql_connect returns false
//rather than if mysql_error() exists, but this is to show
// what happens.

Expected result:
For the code under write error to database to be run, because mysql_error() should be false if the second connection is made.

Actual result:
The script dies with error: 

You have an error in your SQL syntax near 's place', 'false' at line 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-17 06:16 UTC] moa_hunter at yahoo dot com
By the way, it's the code under //die with error
that is executed, not that the script is dying after the mysql_query line.
Proven by changing the line 
die("Connection error : ".mysql_error());
 [2003-07-17 21:07 UTC]
Please try using this CVS snapshot:
For Windows:

Seems to be fixed in CVS.

 [2003-07-18 00:22 UTC]
mysql_error uses the default connection and reports the error from 1st connection. Currently there is no way to detect error from 2nd connection.

This will be fixed in PHP5.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 25 08:01:30 2024 UTC