php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #17118 mysql_error() tracks errors on last opened link, not last mysql_*() function
Submitted: 2002-05-09 09:44 UTC Modified: 2002-07-01 18:20 UTC
From: mfranzoni at madd dot it Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.2.0 OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mfranzoni at madd dot it
New email:
PHP Version: OS:

 

 [2002-05-09 09:44 UTC] mfranzoni at madd dot it
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();
 
?>

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-05-10 04:35 UTC] sander@php.net
Expected behaviour, making it a docu prob.
 [2002-07-01 18:20 UTC] jan@php.net
This bug has been fixed in CVS. You can grab a snapshot of the
CVS version at http://snaps.php.net/. In case this was a documentation 
problem, the fix will show up soon at http://www.php.net/manual/.
In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites.
Thank you for the report, and for helping us make PHP better.


 [2020-02-07 06:12 UTC] phpdocbot@php.net
Automatic comment on behalf of jan
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=2a7914dcfa080ae3f7eb60b5a6e59aee099962e3
Log: - fix #17118
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Oct 05 13:01:26 2024 UTC