PHP PDO class and XAMPP/”exotic” MySQL configurations
Last night I was trying to setup a @mail server but the installer kept choking when attempting to connect to my local database.
I am posting here my quick workaround in case you too, dear reader, get a dreaded “PDO” error message complaining about your attempt to “connect to unix://”
Here is I how I solved the issue for @mail: I opened library/Zend/Db/Adapter/Pdo/Abstract.php, found the line that creates the PDO object (”new PDO(…“) and, in this example, the first argument passed to the constructor was $dsn.
The problem is that PDO sees that this variables references “localhost” and decides that, since the database is local, it is going to use mysql.sock (hence the unix:// scheme)
This works as long as the file is found in its default location. If it is elsewhere, you are out of luck. This happens, for instance, if you use XAMPP.
Here is my quick fix, inserted right before the creation of the PDO object:
$dsn = str_replace(’host=localhost’, ‘unix_socket=/opt/lampp/var/mysql/mysql.sock’, $dsn);
All done.
Note: I have not investigated enough to know whether this is something missing in the Zend Framework or in @mail itself.
Similar Posts:
- One-line variables swap in PHP, Ruby, Perl, Python and C
- Cheap Server Backup with Amazon S3
- PON or “PHP Object Notation” Is Already Here
- Beware Of A False Sense Of Security
- Php: It’s the Purpose, Stupid.
If you enjoyed this post, make sure you subscribe to my RSS feed!
If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.








Comments
No comments yet.
Leave a comment