Amanada Smith
Amanada Smith

Reputation: 1981

PHP Fatal error: Class 'PDO' not found

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

Upvotes: 68

Views: 243052

Answers (15)

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.

Upvotes: -1

Aris
Aris

Reputation: 5057

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

Upvotes: 1

Justice Selorm Bruce
Justice Selorm Bruce

Reputation: 219

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

Upvotes: -1

Justin
Justin

Reputation: 921

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

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

Upvotes: -1

Wells
Wells

Reputation: 142

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());
}

Upvotes: 3

Hasitha
Hasitha

Reputation: 795

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

Upvotes: 3

user10965860
user10965860

Reputation: 1

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

Upvotes: -1

Alastair Irvine
Alastair Irvine

Reputation: 1176

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)

Upvotes: 22

Nam Nguyen
Nam Nguyen

Reputation: 2498

try

 yum install php-pdo
 yum install php-pdo_mysql

 service httpd restart

Upvotes: 80

Ikhlak S.
Ikhlak S.

Reputation: 9034

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

Upvotes: 3

Pavel Hájek
Pavel Hájek

Reputation: 176

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

Upvotes: 0

Bruno Ribeiro
Bruno Ribeiro

Reputation: 1410

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.

Upvotes: 16

Jo Smo
Jo Smo

Reputation: 7169

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

Upvotes: 76

Stephen
Stephen

Reputation: 18917

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.

Upvotes: 10

Predominant
Predominant

Reputation: 1460

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.

Upvotes: 1

Related Questions