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.
In my case, I was using PDO with php-cli, and it worked fine.
Only when I tried to connect from apache, I got the "missing driver" issue, which I didn't quite understand.
A simple
apt-get install php-mysql
solved it. (Ubuntu 16.04 / PHP7. credits go to the selected answer & Ivan's comment)Hope it can help.
For
PHP 5.5
onCentOS
I fixed this by installing thephp55-mysqlnd
package.For help installing, write a comment as it depends on the way PHP is installed on your system. Available repo's are
webtatic
andremi
.I extremely recommend
mysqllnd
instead ofmysql
because of you would have a lot of problems like number converting and bit type evaluates problem withmysql
extension.on ubuntu install
mysqllnd
with following command:This worked for me.
Just one other thing to confirm as some people are copy/pasting example code from the Internet to get started. Make sure you have MySQL entered here:
In some examples this shows
For those using Symfony2/3 and wondering why you're getting this error. If you're using "mapping_types", you might encounter this error. The reason is that "mapping_types" is placed at the wrong level. For instance :
This "mapping_types" must be placed at this level :
I hope this helps
I found the solution here : https://github.com/doctrine/DoctrineBundle/issues/327