Bug #17118: mysql_error() tracks errors on last opened link, not last mysql_*() function

From: Date: Thu, 09 May 2002 13:44:02 +0000
Subject: Bug #17118: mysql_error() tracks errors on last opened link, not last mysql_*() function
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-7324@lists.php.net to get a copy of this message
From: mfranzoni@madd.it Operating system: PHP version: 4.2.0 PHP Bug Type: MySQL related Bug description: mysql_error() tracks errors on last opened link, not last mysql_*() function when more than one link is opened (to different db) in a php script, if mysql_error() is called without the optional link-id parameter it returns the error status relative to the last opened link whereas documentation states it should be about the last mysql_*() function call. So far it could be just a documentation problem (not clear enough) yet I'd expect mysql_error() to be smart enough to identify the link used by the most recent mysql_*() function rather just than picking the last created one. Obviously the same applies for mysql_errno() doc extract for mysql_error(): -------------------- Returns the error text from the last MySQL function, or '' (the empty string) if no error occurred. [...] Note that this function only returns the error text from the most recently executed MySQL function (not including mysql_error() and mysql_errno()), so if you want to use it, make sure you check the value before calling another MySQL function. Script ---- Here is a simple script to play with to view what I probably made less understandable by writing... Usage: test.tab1 and guestbook.book db's and tables must be there, the no_*such_table's table should generate an error... altering the order of connections changes the output as well. <? print "\nDB1\n"; $db1 = mysql_connect("localhost", "user", "user"); print mysql_error(); mysql_select_db("test"); print mysql_error(); print "\nDB2\n"; $db2 = mysql_connect("localhost", "guest", "guest"); print mysql_error(); mysql_select_db("guestbook"); print mysql_error(); print "\nQUERY1.1\n"; mysql_query("select * from tab1", $db1); print mysql_error(); print "\nQUERY1.2\n"; mysql_query("select * from no_1such_table", $db1); print mysql_error(); print "\nQUERY2.1\n"; mysql_query("select * from book", $db2); print mysql_error(); print "\nQUERY2.2\n"; mysql_query("select * from no_2such_table", $db2); print mysql_error(); print "\nQUERY1.1\n"; mysql_query("select * from tab1", $db1); print mysql_error(); print "\nQUERY1.2\n"; mysql_query("select * from no_3such_table", $db1); print mysql_error(); ?> -- Edit bug report at http://bugs.php.net/?id=17118&edit=1 -- Fixed in CVS: http://bugs.php.net/fix.php?id=17118&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=17118&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=17118&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=17118&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=17118&r=support Expected behavior: http://bugs.php.net/fix.php?id=17118&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=17118&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=17118&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=17118&r=globals

« previous php.bugs (#7324) next »