Mysqli small fix for allowing socket in Zend Framework

As this site is running on ICDSoft hosting, they allow to use MySQL 5 or MySQL 4, but they provide different sockets for each version.

In MySQLi extension, the following host string doesn’t works: localhost:/tmp/mysql5.sock (or localhost:/tmp/mysql.sock), this because they separate the socket from the server host string.

In Zend Framework in the MySQLi Adapter, they don’t use the socket optional parameter, so I made a small fix to allow this [Zend/Db/Adapter/Mysqli.php]:

if (isset($this->_config['port'])) {$port = (integer) $this->_config['port'];

} else {

$port = null;

}/* new block */

if (isset($this->_config['socket'])) {

$socket = $this->_config['socket'];

} else {

$socket = null;


/* end of new block */

// Suppress connection warnings here.

// Throw an exception instead.

@$this->_connection = new mysqli(






$socket //new


This allow you to use the socket name, this was for enabling my new showcase example: Google Maps and GeoIP Location, you can see the full code here:

  • Nick

    Great write up, I needed this. Although I dislike having to use sockets for my connection, I wonder why this is not in the ZF build to begin with.

  • Huey

    You can set the default socket using php.ini

    mysqli.default_socket = /whatever/you/want

    I think ZF left it out because it was easy to change in this manner?