Dave Perrett

Installing MySql/PDO for PHP

database, linux, php, programming, web

I was getting something like this trying to run an application built on the Zend Framework :

1
2
3
4
5
6
7
8
9
10
11
Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message
'The PDO extension is required for this adapter but not loaded' in
/usr/share/ZendFramework-0.9.1-Beta/library/Zend/Db/Adapter/Pdo/Abstract.php:74
Stack trace:
#0 /usr/share/ZendFramework-0.9.1-Beta/library/Zend/Db/Adapter/Abstract.php(143): Zend_Db_Adapter_Pdo_Abstract->_connect()
#1 /usr/share/ZendFramework-0.9.1-Beta/library/Zend/Db/Adapter/Pdo/Abstract.php(154): Zend_Db_Adapter_Abstract->query('DESCRIBE `album...', Array)
#2 /usr/share/ZendFramework-0.9.1-Beta/library/Zend/Db/Adapter/Pdo/Mysql.php(106): Zend_Db_Adapter_Pdo_Abstract->query('DESCRIBE `album...')
#3 /usr/share/ZendFramework-0.9.1-Beta/library/Zend/Db/Table/Abstract.php(414): Zend_Db_Adapter_Pdo_Mysql->describeTable('album', NULL)
#4 /usr/share/ZendFramework-0.9.1-Beta/library/Zend/Db/Table/Abstract.php(356): Zend_Db_Table_Abstract->_setupMetadata()
#5 /usr/share/ZendFramework-0.9.1-Beta/library/Zend/Db/Table/Abstract.php(219): Zend_Db_Table_Abstract->_setup()
#6 /home/dave/php/dcj_f in /usr/share/ZendFramework-0.9.1-Beta/library/Zend/Db/Adapter/Pdo/Abstract.php on line 74

The solution is here (Joel’s Corner).

1
2
3
4
5
$ sudo apt-get install php5-dev
$ sudo apt-get install php-pear
$ sudo apt-get install libmysqlclient15-dev
$ sudo pecl install pdo
$ PHP_PDO_SHARED=1 sudo pecl install pdo_mysql

Then, add these lines to php.ini somewhere to activate the new modules :

1
2
extension=pdo.so
extension=pdo_mysql.so