ID:               24689
 User updated by:  moa_hunter at yahoo dot com
 Reported By:      moa_hunter at yahoo dot com
 Status:           Open
 Bug Type:         MySQL related
 Operating System: Linux from source, 2.4.21
 PHP Version:      4.3.2
 New Comment:

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());


Previous Comments:
------------------------------------------------------------------------

[2003-07-17 06:08:14] 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


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=24689&edit=1

Reply via email to