An exception occurred in the driver: could not find driver [duplicate]
Solution 1:
You need to have a module called pdo_mysql. Looking for following in phpinfo(),
pdo_mysql
PDO Driver for MySQL, client library version => 5.1.44
Solution 2:
The dsn in your code reveals you are trying to connect with the mysql driver. Your error message indicates that this driver is unavailable.
Check that you have the mysql extension installed on your server.
In Ubuntu/Debian you check for the package with:
dpkg --get-selections | grep php | grep mysql
Install the php5-mysql package if you do not have it.
In Ubuntu/Debian you can use:
- PHP5:
sudo apt-get install php5-mysql
- PHP7:
sudo apt-get install php7.0-mysql
Lastly, to get it working, you will need to restart your web-server:
- Apache:
sudo /etc/init.d/apache2 restart
- Nginx:
sudo /etc/init.d/nginx restart
Solution 3:
Update: newer versions should use php-sqlite3
package instead of php5-sqlite
. So use this, if you are using a recent ubuntu version:
sudo apt-get install sqlite php-sqlite3
Original answer to question is here:
sudo apt-get install sqlite php5-sqlite
sudo /etc/init.d/apache2 restart
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.