Problem:
Users encounter a PDOException with the message "could not find driver" when attempting to connect to a MySQL database using the PDO extension in PHP.
Code:
1 |
|
Cause:
The error is most likely caused by the absence of the necessary PDO driver for MySQL (pdo_mysql).
Solution:
To resolve the issue, the pdo_mysql module needs to be installed and enabled in PHP.
Steps:
If not installed, use the PECL command to install it:
1 |
|
Edit the php.ini file and uncomment the following line to enable it:
1 |
|
Example:
1 |
|
Note:
Make sure to replace sudo with your preferred root user command if necessary.
The above is the detailed content of Why Am I Getting a 'could not find driver' PDOException When Connecting to MySQL?. For more information, please follow other related articles on the PHP Chinese website!