Zend Server Mysql Socket problem with PDO [Solved]

Zend Server Mysql Socket problem with PDO [Solved]

Hold on Cowboy

This blog post is pretty old. Be careful with the information you find in here. It's likely dead, dying, or wildly inaccurate.

The Problem

This answer has eluded me for months. I have Zend Server CE installed on my Mac (and linux web servers). I would use a DSN similar to the following (please note that my real password is not ‘root’).

mysql://root:root@localhost/thedatabase

This would result in an error in a PHP Fatal error of

'Can't connect to local MySQL server through socket '/tmp/mysql.sock''

This drove me mad looking for an answer. I had not configured it to connect through a socket, why was it doing that? To add more injury to this insult, if I tried to connect to Zend Server’s mysql socket (/usr/local/zend/mysql/tmp/mysql.sock) I would still get the same error message.

The Best Solution

It’s as simple as specifying 127.0.0.1 in replace of localhost. I guess if you do this, you force PDO to use a TCP connection.

Solution Alternative

I haven’t tried this, but you could also symlink from

/tmp/mysql.sock

to

/usr/local/zend/mysql/tmp/mysql.sock

.

I’m not a big fan of symlinks that reach outside of the application.

Cause

It seems there is a bug in PDO PHP 5.2.x that is not fixed until 5.3.x.

Resources: http://forums.zend.com/viewtopic.php?f=44&t=568