|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 20:00:01 2025 UTC |
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());