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

Issue Type: Bug Created: 2008-08-18T08:20:17.000+0000 Last Updated: 2012-03-21T11:09:21.000+0000 Status: Resolved Fix version(s): - 1.8.2 (27/May/09)

Reporter: Olivier Doucet (ezameku) Assignee: Satoru Yoshida (satoruyoshida) Tags: - Zend_Db_Adapter_Mysqli

Related issues: - ZF-5342



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

<pre class="highlight">
        @$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


Posted by Olivier Doucet (ezameku) on 2008-08-20T06:15:50.000+0000

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

Posted by S├ębastien Vanvelthem (belgattitude) on 2008-12-23T06:19:56.000+0000

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



Posted by old of Satoru Yoshida ( on 2009-05-11T23:07:09.000+0000

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

Posted by old of Satoru Yoshida ( on 2009-05-15T18:28:50.000+0000

Solved in SVN r15598

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.