PDO_Mysql error with Zend Server and socket

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.

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

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, haveing a different application.ini on the server and on then on my local devel machine.

Ugggg.

Comments

The solution (for me) It's

The solution (for me)
It's been kinda pesky for me too. Here's what I do in application.ini to make it ok:

[bootstrap]
; all your common settings go here in [bootstrap] and you extend this 
; environment with each additional environment you set up.
resources.db.adapter = "pdo_mysql"
resources.db.isDefaultTableAdapter = true
 
[development : bootstrap]
resources.db.params.unix_socket = "/usr/local/zend/mysql/tmp/mysql.sock"
resources.db.params.username = "your_user"
resources.db.params.password = "your_pass"
resources.db.params.dbname = "your_database"
 
[testing : bootstrap]
resources.db.params.host = "localhost"
resources.db.params.username = "your_user"
resources.db.params.password = "your_pass"
resources.db.params.dbname = "your_database"
 
[production : bootstrap]
resources.db.params.host = "mysql.your-site.com"
resources.db.params.username = "your_user"
resources.db.params.password = "your_pass"
resources.db.params.dbname = "your_database"

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <drupal5>, <drupal6>, <javascript>, <php>, <sql>. Beside the tag style "<foo>" it is also possible to use "[foo]".

More information about formatting options