PDO_Mysql error with Zend Server and socket

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.

I’ve headed this issue off before, but now I think I know why it happens.

The problem 

With a new install of Zend Server on my Mac and trying to access a DB with my Zend Framework web app I am greeted with an error of

Message: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)" when trying to run our application.

This was rather frustrating as I changed all instances of mysql_default_socket in the PHP settings (php.ini). It still didn’t pick up the location of the socket. Since I’m using PDO, it looks like this is an issue in PHP 5.2 for PDO.


The work around for me has been to declare the socket in my application.ini file

resources.db.params.unix_socket = "/usr/local/zend/mysql/tmp/mysql.sock"

The problem this introduces, having a different application.ini on the server and on then on my local devel machine.


Did this help you out? It took me a few days to piece together all this information together, I hope this saves you some time (who knows, maybe the future me will be thankful I wrote this down). Let me know your thoughts. shanestillwell@gmail.com