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
This question is related to
php
mysql
cakephp
web-applications
I had to run the following on AWS EC2 Linux instance (PHP Version 7.3):
sudo yum install php73-php-pdo php73-php-mysqlnd
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.
Try adding use PDO;
after your namespace or just before your class or at the top of your PHP
file.
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:
If you run php with php-fpm module,do not forget to run command systemctl restart php-fpm!That will reload php-fpm module.
If you have upgraded your PHP version, make sure that the old PHP version configuration in your .htaccess has been deleted. For more info, check this https://www.hostgator.com/help/article/php-configuration-plugin
I solved it with library PHP_PDO , because my hosting provider didn't accept my requirement for installation of PDO driver to apache server.
try
yum install php-pdo
yum install php-pdo_mysql
service httpd restart
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.
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());
}
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.
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
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
.
Source: Stackoverflow.com