MySQL Problem retrieving errno, when connect fails + solution

From: Date: Thu, 01 Jan 1970 00:00:00 +0000
Subject: MySQL Problem retrieving errno, when connect fails + solution
Groups: php.internals 
Request: Send a blank email to internals+get-3760@lists.php.net to get a copy of this message
Hi, There is a problem in the MySQL extension when trying to get the errno, if the connection failed, if a prior mysql_connect() call already succeeded: mysql_connect('host', 'user', 'pw'); mysql_connect('host2', 'user2', 'pw2'); echo mysql_errno(); echo mysql_error(); Assuming the first call succeeds, but the second fails, then mysql_errno() just returns 0, but it shouldn't. That's because mysql_errno() uses the default_link for getting the errno in this case. There are two possible solutions: 1. set the default_link to -1 before makeing a new connection 2. change mysql_errno, with something like: ... snip ... case 1: if (zend_get_parameters_ex(1, &mysql_link)==FAILURE) { if (MySG(connect_errno)!=0){ RETURN_LONG(MySG(connect_errno)); } else { RETURN_FALSE; } } id = -1; break; ... I think 1. would be the better solution because 2. is only a workaround, or not? thanx, bye, -- ------------------------------- ---------------------------------- Michael Bretterklieber - http://www.bretterklieber.com JAWA Management Software GmbH - http://www.jawa.at Tel: ++43-(0)316-403274-12 - GSM: ++43-(0)676-84 03 15 712 ------------------------------- ---------------------------------- "...the number of UNIX installations has grown to 10, with more expected..." - Dennis Ritchie and Ken Thompson, June 1972

« previous php.internals (#3760) next »