ID: 24689
Updated by: [email]georgphp.net[/email]
Reported By: moa_hunter at yahoo dot com
-Status: Closed
+Status: Wont fix
Bug Type: MySQL related
Operating System: Linux from source, 2.4.21
PHP Version: 4.3.2
New Comment:

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.


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

[2003-07-17 21:07:33] [email]sniperphp.net[/email]

Please try using this CVS snapshot:

[url]http://snaps.php.net/php4-STABLE-latest.tar.gz[/url]

For Windows:

[url]http://snaps.php.net/win32/php4-win32-STABLE-latest.zip[/url]

Seems to be fixed in CVS.


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

[2003-07-17 06:16:18] 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 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 [url]http://bugs.php.net/?id=24689&edit=1[/url]