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.
Update: newer versions should use
php-sqlite3
package instead ofphp5-sqlite
. So use this, if you are using a recent ubuntu version:Original answer to question is here:
If your phpinfo() is not showing the pdo_sqlite line (in my case, on my Ubuntu Server), you just need to run the lines above and then you'll be good to go.
Incorrect installation of PHP was being called
I was experiencing the same problem. And I hope this would help someone who is having a similar issue as me.
Scenario
I created
phpinfo.php
file in thepublic
folder and run thephpinfo()
to look for the location of myphp.ini
file.PHP.ini Location =
c:\xampp\php\php.ini
Problem
Calling
c:\xampp\htdocs> php -v
returnedPHP 7.2.3
butphpinfo.php
showedPHP 7.2.2
.Solution
Instead of calling
which gave me this error, I used
and it worked.
Did you check your php.ini (check for the correct location with phpinfo()) if MySQL and the driver is installed correctly?
I had the same issue. The solution depends on OS. In my case, i have debian, so to solve it:
Install php-mysql and php7.0-mysql
I edited my
php.ini
locate at /etc/php/7.0/apache2/php.iniThen restart apache:
This solves my problem
I faced the same issue after I removed the php5 package (that includes all the drivers as well) in order to install php7 package. I actually installed php7 package without a mysql module.
I managed to solve it by typing in the terminal:
1) $ apt-cache search php7 which lists all the modules, looking through the modules I found,
php7.0-mysql - MySQL module for PHP
2) $ sudo apt-get install php7.0-mysql
That's it. It worked for me in my linux system.
(use the appropriate php version, yours could be php5)
for Windows 8.1/10 in :\\php.ini file you should uncomment line "extension=pdo_mysql"