PHP Fatal error: Class 'PDO' not found

PhpMysqlCakephpWeb Applications

Php Problem Overview


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

Php Solutions


Solution 1 - Php

try

 yum install php-pdo
 yum install php-pdo_mysql

 service httpd restart

Solution 2 - Php

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

Solution 3 - Php

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 - Php

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 - Php

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.

Solution 6 - Php

I had the same problem on GoDaddy. I added the extension=pdo.so to php.ini, still didn't work. And then only one thing came to my mind: Permissions

>Before uploading the file, kill all PHP processes(cPanel->PHP Processes).

The problem was that with the file permissions, it was set to 0644 and was not executable . You need to set the file permission at least 0755.

Permissions

Solution 7 - Php

Its a Little Late but I found the same problem and i fixed it by a "" in front of PDO

public function enabled() {
    return in_array('mysql', \PDO::getAvailableDrivers());
}

Solution 8 - Php

you can just find-out loaded config file by executing below command,

 php -i | grep 'php.ini'

Then add below lines to correct php.ini file

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

Then restart web server,

service httpd restart

Solution 9 - Php

This error is caused by PDO not being available to PHP.

If you are getting the error on the command line, or not via the same interface your website uses for PHP, you are potentially invoking a different version of PHP, or utlising a different php.ini configuration file when checking phpinfo().

Ensure PDO is loaded, and the PDO drivers for your database are also loaded.

Solution 10 - Php

I solved it with library PHP_PDO , because my hosting provider didn't accept my requirement for installation of PDO driver to apache server.

Solution 11 - Php

If you run php with php-fpm module,do not forget to run command systemctl restart php-fpm!That will reload php-fpm module.

Solution 12 - Php

I had to run the following on AWS EC2 Linux instance (PHP Version 7.3):

sudo yum install php73-php-pdo php73-php-mysqlnd

Solution 13 - Php

If anyone getting this error in cPanel, please check the PHP version type in your cPanel. Change it, alt-php to ea-php. This setting worked for me.

Solution 14 - Php

After a long time, I finally solved it. check your folder in Cpanel to see if there is a php.ini file. if yes delete it since Cpanel will be using its own php.ini

Solution 15 - Php

For Fedora 33 you can install as follows:

Install

dnf install php-pdo
dnf install php-pdo_mysql

Restart PHP

systemctl restart php-fpm.service

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAmanada SmithView Question on Stackoverflow
Solution 1 - PhpBảo NamView Answer on Stackoverflow
Solution 2 - PhpJo SmoView Answer on Stackoverflow
Solution 3 - PhpAlastair IrvineView Answer on Stackoverflow
Solution 4 - PhpBruno RibeiroView Answer on Stackoverflow
Solution 5 - PhpStephenView Answer on Stackoverflow
Solution 6 - PhpRustyView Answer on Stackoverflow
Solution 7 - PhpWellsView Answer on Stackoverflow
Solution 8 - PhpHasithaView Answer on Stackoverflow
Solution 9 - PhpPredominantView Answer on Stackoverflow
Solution 10 - PhpPavel HájekView Answer on Stackoverflow
Solution 11 - Phpuser10965860View Answer on Stackoverflow
Solution 12 - PhpJustinView Answer on Stackoverflow
Solution 13 - PhpMozammel Hoque NasifView Answer on Stackoverflow
Solution 14 - PhpJustice Selorm BruceView Answer on Stackoverflow
Solution 15 - PhpArisView Answer on Stackoverflow