From: moa_hunter at yahoo dot com
Operating system: Linux from source, 2.4.21
PHP version: 4.3.2
PHP Bug Type: MySQL related
Bug description: mysql_connect() doesn't set mysql_error() to false on valid connect
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 bug report at http://bugs.php.net/?id=24689&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=24689&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=24689&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=24689&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=24689&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=24689&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=24689&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=24689&r=support
Expected behavior: http://bugs.php.net/fix.php?id=24689&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=24689&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=24689&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=24689&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=24689&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=24689&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=24689&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=24689&r=gnused