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

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());
}

PS: take a look at ZF-3984, this attempt brings a solution for that (mysqli_real_escape wont't be called, the exception will be thrown as expected), but there's maybe some reasons to look deeper, to see why the quote method was called even if the connection failed (lazy connect mode ?).

Posted by old of Satoru Yoshida (yoshida@zend.co.jp) on 2009-05-11T23:07:31.000+0000

Is this still active?
The description seems to be outdated.

Posted by old of Satoru Yoshida (yoshida@zend.co.jp) on 2009-05-15T18:32:46.000+0000