Mysqli small fix for allowing socket in Zend Framework
Monday, December 31st, 2007As 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(
$this->_config['host'],
$this->_config['username'],
$this->_config['password'],
$this->_config['dbname'],
$port,
$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: http://blog.danguer.com/files/Zend_Db_Adapter/Mysqli.phps


