php.net |  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
Votes:2
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
 [2003-07-17 06:08 UTC] moa_hunter at yahoo dot com
Description:
------------
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");
mysql_select_db("main_student_data");
$query = "INSERT INTO  VALUES('0012', 'Mike's place', 'false')";
mysql_query($query);
if(mysql_error())
{
  $con_id_2 = mysql_connect("localhost", "someuser", "apass");
  if(mysql_error())
  {
    //abort with error
    die(mysql_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

Patches

Pull Requests

History

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(mysql_error()); 
to 
die("Connection error : ".mysql_error());
 [2003-07-17 21:07 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

Seems to be fixed in CVS.

 [2003-07-18 00:22 UTC] georg@php.net
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 Oct 03 17:01:26 2024 UTC