Issue:
could not find driver while trying to connect to MySQL using PDO.
Resolution
There might be few possible causes for this issue. Mostly this issue arises with improper configuration in php.ini file or your connection string (DSN – Data Source Name)
- In your php.ini file make sure that PDO extension for MySQL is enabled. You will see something like this if its enabled extension=pdo_mysql if you see semicolon in front remove it and restart Apache.
- If everything is correct and your phpinfo() is showing that this extension is enabled then make sure that you dsn is correct and there is not typos. A sample dsn is given below to connect to MySQL.
$pdo = new PDO('mysql:host=127.0.0.1;dbname=your_db_name;port=3306', 'db_user', 'db_pass');