I have just installed Debian Lenny with Apache, MySQL, and PHP and I am receiving a PDOException could not find driver
.
This is the specific line of code it is referring to:
$dbh = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS)
DB_HOST
, DB_NAME
, DB_USER
, and DB_PASS
are constants that I have defined. It works fine on the production server (and on my previous Ubuntu Server setup).
Is this something to do with my PHP installation?
Searching the internet has not helped, all I get is experts-exchange and examples, but no solutions.
When adding these into your php.ini ensure the php_pdo.dll reference is first before the db drivers dlls otherwise this will also cause this error message too. Add them like this:
I had the same problem during running tests with separate php.ini. I had to add these lines to my own php.ini file:
Notice: Exactly in this order
If you are using sqlite for testing you will need php sqlite pdo drive. You can install them as below.
For Ubuntu 14.04
In ubuntu 16.04 there is no
php5-sqlite
Check if extension_dir in php configuration file set correctly. Try to comment/uncomment some extensions and see if it's reflected on phpinfo(). If it doesn't then either php config file cannot be loaded (wrong location) extension_dir is commented or set to the wrong location.
The problem is a missing php to mysql library. In CentOs i fixed it by running
# yum install php-mysql
and then restarting apache with# /bin/systemctl restart httpd.service
Note that the naming is slightly different from debian/ubuntu based distros, php->php5 and httpd->apache2.On my Windows machine, I had to give the absolute path to the extension dir in my php.ini:
extension_dir = "c:\php5\ext"