Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.7.1
-
Fix Version/s: 1.8.2
-
Component/s: Zend_Db_Adapter_Mysqli
-
Labels:None
Description
Just found a minor issue with MySQLi::connect().
The test made to see if the mysqli connection succeed is based on 2 conditions : $this->_connection and mysqli_connect_errno(). In case of failure with mysql_connect_errno(), we need to clear/unset the value of $this->_connection (which is a "false" mysqli object = an empty mysqli object with no real link to the database - sorry for approximative english
.
The problem is that the entire class relies on existence of $this->_connection to see if the connection is active. In some circumstances, (i.e. ZF-3984) the connection exception can be catched by a calling class and ignored, all subsequent calls will think that the connection is effective (because Mysqli::_connection is an object) and write warnings which are undesirable and hard to debug.
I think fixing the bug is just one line... read the proposed solution below and hope that it will work
Thanks to Zend guys, it's an amazing job you do...
Seb
Solution attempt :
[original]
if ($this->_connection === false || mysqli_connect_errno()) { require_once 'Zend/Db/Adapter/Mysqli/Exception.php'; throw new Zend_Db_Adapter_Mysqli_Exception(mysqli_connect_error()); }
[patched]
if ($this->_connection === false || mysqli_connect_errno()) { // THE connection error was given with mysqli_connect_errno, the value of $this->_connection is a "invalid" mysqli object. So I reset it $this->_connection = false; require_once 'Zend/Db/Adapter/Mysqli/Exception.php'; throw new Zend_Db_Adapter_Mysqli_Exception(mysqli_connect_error()); }
Issue Links
| This issue is related to: | ||||
| ZF-3984 | connection control not sufficient in case of "Too many open links". |
|
|
|
An example of the same issue when database connection fails because of "Too many open links".