ZF-3984: connection control not sufficient in case of "Too many open links".


On Zend/Db/Adapter/Mysqli.php, around line 302 :

        @$this->_connection = new mysqli(
if ($this->_connection === false || mysqli_connect_errno()) {

I'm using this, but I'm using too many links at the same time (the error that mysqlclient is returning is "Too many open links". BUT $this->_connection is not false (new mysqli() is returning mysqli Object ( ) as if everything was OK), and mysqli_connect_errno() does not return anything.

There should be a better control to check whether the connection is absolutely perfect or not. I personnaly think that this may be a PHP bug (new mysqli() should return false), but I posted it here in case.

php.ini config, related to Mysqli : [mysqli] mysqli.max_links = 3 mysqli.reconnect = On


I made some additional tests.

When the connection is OK, new mysqli() is returning a mysqli Object(). When the error appears, the same object is returned, but cannot be used. Example :

real_escape_string() [function.mysqli-real-escape-string]: Couldn't fetch mysqli in Zend/Db/Adapter/Mysqli.php on line 114

I can confirm this issue at least on PHP 5.2.6 / Linux. As you said it happens only when the connection is not effective (failed because database not reachable, invalid login...). I don't agree with you on the fact that this is probably a PHP MySQLi related issue.

The problem is that when calling Zend_Db_Adapter_MySQLi::_connect(), we forget to unset the problematic mysqli object, let's see in ZF1.7.1 ::

    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 version

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

I'll post a separate bug report for this issue, hope this solution works



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

Solved in SVN r15598