Native PHP / Mysql installation on Mac, activating the PDO driver
mysql, mysqli, pdo, php
Solution
The solution was to do the following:
- Change .sock path in php.ini to reflect the actual path
- Restart your computer, not just apache
It appears the php.ini changes did not load while doing
$ sudo apachectl restart
and needed the Macbook to reboot before it took them into account.
Problem
I have a custom installation on the MacOSX Lion consisting of the following: - Native PHP upgraded to 5.4, works like a charm. - Installed MySQL, being run from /usr/local/mysql-5.5.25-osx10.6-x86_64/bin/mysql, works like a charm, Workbench connects and can do ops. Edited php.ini in /etc/ to activate the following: ``` extension=php_mysqli.so extension=php_pdo_pgsql.so extension=php_pdo_mysql.so ``` phpinfo() says the following: PDO PDO support enabled PDO drivers mysql, pgsql, sqlite pdo_mysql PDO Driver for MySQL enabled Client API version mysqlnd 5.0.10 - 20111026 - $Id: b0b3b15c693b7f6aeb3aa66b646fee339f175e39 $ Directive Local Value Master Value pdo_mysql.default_socket /var/mysql/mysql.sock /var/mysql/mysql.sock That means it works, yes? Two problems though: No such file as /var/mysql/mysql.sock, it's in /tmp/mysql.sock. But I configured and built php with the PDO options on: --with-mysql=mysqlnd --with-mysqli=mysqlnd --without-pear --with-pdo-mysql=mysqlnd --with-mysql-sock=/var/mysql/mysql.sock. No effect if I change the ini setting to /tmp/mysql.sock, it's reflected in php.ini, but the error stays exactly the same. When I try to instantiate the PDO class inside PHP, this happens: Uncaught exception 'PDOException' with message 'could not find driver' When I try accessing MySQL from PHP in an old school mysqli kind of way, I get this: Failed to connect to MySQL: (2002) No such file or directory Warning: main(): Couldn't fetch mysqli in... What else can I try to make my PHP and my MySQL play nice?