Hi all. This bug was marked as Bogus, but is a real concern for us at ABR, as we may use many different databases on different servers in the course of generating a page using php.
The long and the short of it is, we can't get an error message if connecting to a database fails, after we have already connected to a different database. Obviously we can't pass the linkID to the second db to mysql_error, becuase on a connection failure, linkID is FALSE. The desired behavior would be that the mysql_error and mysql_errno functions would have knowledge of a mysql_connect() failure, and report the error returned from the failed mysql_connect() - not to look at errors of the currently opened, and therefore default, database. Regards, Stephen Thorne. http://bugs.php.net/?id=22651 ID: 22651 User updated by: craigs at abr dot com dot au Reported By: craigs at abr dot com dot au Status: Bogus Bug Type: MySQL related Operating System: Redhat Linux Adv Serv 2.1AS PHP Version: 4.2.3 New Comment: So basically you are saying that even though mysql_error is now meant to report connect errors (as of 4.0.6), it is not meant to report connect errors if a link already exists from a previous connection to a different server? So now, mysql_error only sometimes returns errors from calls to the mysql_connect function(since 4.0.6)? Previous Comments: ------------------------------------------------------------------------ [2003-03-11 23:34:32] [EMAIL PROTECTED] You guess wrong. The default link won't change if the mysql_connect() fails. (of course not) And as it's still that $LinkID, and no errors happened for THAT one, then mysql_error() and mysql_errno() will of course print nothing. ------------------------------------------------------------------------ [2003-03-11 22:52:34] craigs at abr dot com dot au Calling mysql_errno or mysql_error after a failed mysql_connect when there is an already existing mysql connection resource does not return any error message for the failed connect. According to the doco, it would be expected to return an error such as 'Unknown Mysql Server Host'. I have searched the bug database, and bugs 2051 and 10291 report a related issue of mysql_error/errno not reporting mysql_connect errors, however a review of the change log reports support for mysql_connect errors was added in 4.0.6. A code segment that reproduces this bug follows ======================== $LinkID = mysql_connect("localhost","login","password"); mysql_select_db("mysql"); mysql_query("SELECT * FROM user"); $LinkID2 = mysql_connect("badserver","login","password"); echo "Mysql Error: ".mysql_errno()." - ".mysql_error()."\n"; ================== Expected result- Mysql Error: 2005 - Unknown MySQL Server Host 'badserver' (1) Actual Result - Mysql Error: 0 - Commenting out the first 3 lines and re running the script returns the expected error of unknown server. I would guess that the mysql_error functions use of a default link resource of the last open resource is at fault, as none is opened in the connect. Cheers Craig ------------------------------------------------------------------------ ------------------------------------------------------- -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, visit: http://www.php.net/unsub.php