I needed to get PHP to talk to MySQL through PDO on an AWS Ubuntu instance.
Here was my initial error:
PHP Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'
This means that PDO didn't have the right driver. In this case, MySQL.
What version of PHP was I running?
$ php -v
PHP 5.3.2-1ubuntu4.9 with Suhosin-Patch (cli) (built: May 3 2011 00:45:52)
I tried to install PDO, just in case:
$ sudo pecl install pdo
[Some stuff excluded for brevity]
make: *** [pdo_dbh.lo] Error 1 ERROR: `make' failed
That just means that PDO is already baked into PHP 5.3, so we don't have to install PDO at all. Ok, so let's install the pdo_mysql driver the old fashioned way.
$ sudo pecl install pdo_mysql
[Some stuff excluded for brevity]
checking for PDO includes... checking for PDO includes...
configure: error: Cannot find php_pdo_driver.h.
ERROR: `/tmp/pear/temp/PDO_MYSQL/configure' failed
No love, and searching for the error didn't tell me what I needed to know: the pdo_mysql driver is included in the php5-mysql package on ubuntu. It's not explicitly obvious.
sudo apt-get install php5-mysql
I also restarted apache, even though it looked like apt did it for me, but after that, no more errors.
0 Responses to MySQL drivers for PDO in PHP 5.3+ on Ubuntu
Leave a Reply