Home > Database > Mysql Tutorial > How to Fix the 'Could Not Find Driver' PDO Error in PHP?

How to Fix the 'Could Not Find Driver' PDO Error in PHP?

DDD
Release: 2024-12-21 01:51:09
Original
654 people have browsed it

How to Fix the

PDO Error: "Could Not Find Driver" Solved with pdo_mysql Module

Issue:

Upon attempting to connect to a MySQL database using PHP's PDO extension on a Debian Lenny server, developers may encounter a PDOException with the message "could not find driver." This error occurs at the line:

$dbh = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS)
Copy after login

Solution:

The issue arises from the absence of the pdo_mysql module in PHP. To resolve it, check phpinfo() for the following:

pdo_mysql

PDO Driver for MySQL, client library version => 5.1.44
Copy after login

If the pdo_mysql module is missing, proceed with the following steps:

  1. Install the PHP MySQL extension using the appropriate command for your operating system:

    • Ubuntu/Debian: sudo apt-get install php-mysql
    • CentOS: yum install php-mysql
  2. Restart Apache:

    • Ubuntu/Debian: sudo service apache2 restart
    • CentOS: sudo service httpd restart

After completing these steps, the pdo_mysql module should be available, and the PDO connection should establish without encountering the "could not find driver" error.

The above is the detailed content of How to Fix the 'Could Not Find Driver' PDO Error in PHP?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template