PHP Fatal error: Class 'PDO' not found

188,498

Solution 1

try

 yum install php-pdo
 yum install php-pdo_mysql

 service httpd restart

Solution 2

Try adding use PDO; after your namespace or just before your class or at the top of your PHP file.

Solution 3

This can also happen if there is a php.ini file in the web app's current working directory. If one has been placed there to change certain settings, it will override the global one.

To avoid this problem, don't use a php.ini file to change settings; instead you can:

  • Specify settings in the vhost declaration
  • Use an .htaccess file with php_flag (see here)
  • Use an .user.ini file (see here)

Solution 4

Ensure they are being called in the php.ini file

If the PDO is displayed in the list of currently installed php modules, you will want to check the php.ini file in the relevant folder to ensure they are being called. Somewhere in the php.ini file you should see the following:

extension=pdo.so
extension=pdo_sqlite.so
extension=pdo_mysql.so
extension=sqlite.so

If they are not present, simply add the lines above to the bottom of the php.ini file and save it.

Solution 5

What is the full source of the file Mysql.php. Based on the output of the php info list, it sounds like you may be trying to reference a global class from within a namespace.

If the file Mysql.php has a statement "namespace " in it, use \PDO in place of PDO - this will tell PHP to look for a global class, rather than looking in the local namespace.

Share:
188,498
Amanada Smith
Author by

Amanada Smith

Updated on November 30, 2021

Comments

  • Amanada Smith
    Amanada Smith over 2 years
    PHP Fatal error:  Class 'PDO' not found in /home/bd/public_html/app/webroot/Cake/Model/Datasource/Database/Mysql.php on line 177
    

    PHP INFO:

    PDO
    
    PDO support => enabled
    PDO drivers => sqlite, sqlite2, mysql
    
    pdo_mysql
    
    PDO Driver for MySQL => enabled
    Client API version => 5.5.24
    
    Directive => Local Value => Master Value
    pdo_mysql.default_socket => /var/lib/mysql/mysql.sock => /var/lib/mysql/mysql.sock
    
    pdo_sqlite
    
    PDO Driver for SQLite 3.x => enabled
    SQLite Library => 3.7.7.1
    

    PHP INI:

    extension=pdo.so
    extension=pdo_sqlite.so
    extension=sqlite.so
    extension=pdo_mysql.so
    

    CODE:

    /**
     * Check whether the MySQL extension is installed/loaded
     *
     * @return boolean
     */
            public function enabled() {
                    return in_array('mysql', PDO::getAvailableDrivers());
            }
    

    Ideas as to why I'm getting this error?

    PHP 5.3.15 CloudLinux/CentOS 6 CPanel