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

asked Aug 5, 2012 at 1:52

Amanada Smith's user avatar

Amanada SmithAmanada Smith

1,8539 gold badges28 silver badges42 bronze badges

8

try

 yum install php-pdo
 yum install php-pdo_mysql

 service httpd restart

sj59's user avatar

sj59

2,0322 gold badges22 silver badges22 bronze badges

answered May 10, 2013 at 4:04

Nam Nguyen's user avatar

Nam NguyenNam Nguyen

2,41221 silver badges17 bronze badges

3

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

answered Jul 5, 2014 at 15:54

Jo Smo's user avatar

Jo SmoJo Smo

6,6439 gold badges43 silver badges66 bronze badges

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)

Simon East's user avatar

Simon East

54.1k17 gold badges138 silver badges132 bronze badges

answered Mar 7, 2013 at 6:39

Alastair Irvine's user avatar

2

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.

answered Jan 2, 2015 at 19:16

Bruno Ribeiro's user avatar

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.

answered Aug 6, 2012 at 5:35

Stephen's user avatar

StephenStephen

18.3k4 gold badges31 silver badges32 bronze badges

2

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

answered Jun 25, 2016 at 11:37

Rusty's user avatar

RustyRusty

8,29210 gold badges57 silver badges75 bronze badges

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

answered Apr 23, 2019 at 17:23

Hasitha's user avatar

HasithaHasitha

6988 silver badges16 bronze badges

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

Dharman's user avatar

Dharman

29.3k21 gold badges80 silver badges131 bronze badges

answered Mar 19, 2020 at 19:46

Wells's user avatar

WellsWells

1321 silver badge13 bronze badges

2

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.

answered Aug 6, 2012 at 5:29

Predominant's user avatar

PredominantPredominant

1,46012 silver badges22 bronze badges

3

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

answered Nov 26, 2021 at 19:46

Aris's user avatar

ArisAris

4,4661 gold badge39 silver badges36 bronze badges

3

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

answered Nov 4, 2015 at 13:58

Pavel Hájek's user avatar

4

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

answered Jan 25, 2019 at 6:43

user10965860's user avatar

1

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

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

answered Dec 6, 2020 at 15:20

Justin's user avatar

JustinJustin

8818 silver badges11 bronze badges

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

answered Sep 9, 2021 at 3:41

Justice Selorm Bruce's user avatar

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.

Dharman's user avatar

Dharman

29.3k21 gold badges80 silver badges131 bronze badges

answered Sep 7, 2021 at 6:20

Mozammel Hoque Nasif's user avatar

Fatal error: Class ‘PDO’ not found is an error seen in websites running PHP applications such as Drupal, Prestashop, WordPress, etc. It’ll look something like this:

Fatal error: Class 'PDO' not found in /home/romrac/public_html/drupal/includes/database/database.inc on line 187

This error reports that the web server was unable to locate a PHP module called “PDO” in the server. Web applications require this PHP module to establish a database connection.

At Bobcares’ web server management services, this error is most commonly reported by website owners who use a VPS or a dedicated server to host their site. Server misconfiguration is the common cause of this error, and is mostly seen on newly setup servers.

For instance, in a support request we received recently, the website was recently migrated to a new VPS. The website used Drupal, and the website owner had personally confirmed that all required modules were installed in the VPS.

To troubleshoot, we took a look at the PHP configuration using the phpinfo function. It showed the below output:

Incorrect extension_dir causing Fatal error: Class 'PDO' not found

Incorrect extension_dir causing Fatal error: Class ‘PDO’ not found

As you can see, the modules extension directory is mentioned as “/usr/local/lib/php/extensions/no-debug-non-zts-20130716“, whereas the extension directory for this server was “/usr/lib/php5/20121212“. So, PHP was looking for the PDO extension in the wrong directory. This happened because:

  • The website was using a custom PHP configuration loaded from “/home/romrac/conf/php.ini” instead of the system default “/etc/php5/apache2/php.ini“.
  • The custom PHP configuration was created to match the old server configuration. In the old server had the PHP extensions stored at /usr/local/lib/php/extensions/no-debug-non-zts-20130716. The location was not updated to match the new VPS settings.

To fix this, we could either change the “extension_dir” variable in “/home/romrac/conf/php.ini” to “/usr/local/lib/php/extensions/no-debug-non-zts-20130716“, or we could just disable a custom PHP configuration file. Since this customer used this VPS for just one website, we disabled a custom PHP configuration by removing the entry “PHPINIDir /home/romrac/conf/” from the Apache configuration file.

Other common causes of Fatal error: Class ‘PDO’ not found

As I mentioned earlier, this error is commonly caused by PHP settings mis-configuration. Here are a few scenarios we’ve seen:

The php.ini file missing extension=pdo.so

We’ve seen website owners overwriting fully function php.ini files with default configuration files that came with the Apache package. In such cases, the PHP configuration entry that ENABLES the PDO extension gets over-written.

To detect these issues, we look for the configuration entry “extension=pdo.so” in the active PHP configuration file. For instance, in the above example, we’d look for the “extension=pdo.so” in “/home/romrac/conf/php.ini“.

[ You don’t have to lose your sleep over PHP or MySQL errors in your websites. Get our professional help to fix your site for instantly. ]

PDO module not compiled or missing

In custom configured VPS servers, we’ve seen situations where PHP would not be compiled with a PDO extension, or the modules directory would be the PDO module file. To detect these issues, we look for the file “pdo.so” in the extensions directory, or look at the compiled modules list using the phpinfo() function.

For instance, in the above example, the PHP extensions directory was “/usr/lib/php5/20121212“. So, we’d in that server, we’d look for “pdo.so” in that directory.

[ Never let PHP errors affect your website functioning. Get our professional help to fix your website errors at affordable pricing. ]

Quick resolution of PHP errors

Modern servers use package management systems such as Yum or Apt to efficiently manage PHP configuration. However, customizing these settings for individual websites sometimes can lead to mis-configuration. Our help desk team traces these issues by following what we call “the flow of configuration“.

For example, when troubleshooting an issue in an Apache + mod-PHP server, our team would first check the Apache configuration file to make sure PHP is properly loaded.

Then the primary PHP configuration file (usually located in /etc) is checked to make sure all modules are loaded, the settings are correct, and if it allows user-level over-riding. Then the user’s PHP configuration file is checked to make sure settings are in sync with how the server is configured.

By following a well thought out troubleshooting process, our team is able to resolve such PHP issues within a few minutes, and thereby minimize website downtime.

PHP and MySQL errors giving your websites a hard time?

Don’t let the intermittent website errors affect your business. We’re here to help you.

FIX YOUR WEBSITE ERRORS NOW

var google_conversion_label = «Blp0CLCojHIQ0aD71QM»;

When working with Content Management Systems such as Drupal or other programs in your hosting account, you may run across certain errors during either the initial setup or even after a php or Apache upgrade on your server. One common error you may run across when trying to enter your site is the PDO error. It looks like the one below.

This particular one occurred after an easyapache upgrade of Apache and PHP. Below are the things you should check in order to correct the issue.

  • Check the PHP Modules List to See if It Is Enabled
  • Ensure They Are Being Called in the php.ini File
  • Ensure the php.ini File Is Recursive
  • Check the Extension Directory for PHP
  • Comment Out the extension_dir in php.ini

Check the PHP Modules List to See if It Is Enabled

The first thing we should check is to see if the server has the PDO extensions enabled.

  1. Log into your server via SSH.
  2. Run the command below.
    php -m
  3. You will then be presented with a list of modules currently installed in php, listed alphabetically. Look for PDO in the list. If it exists, then the module is installed.
    mysqlnd
     openssl
     pcre
     PDO
     pdo_mysql
     pdo_sqlite
     Phar
     posix

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.

Ensure the php.ini File Is Recursive

You will next want to ensure that the php.ini file is being used by all the folders and files underneath the main folder. This is known as being recursive. Below is a link to our article on doing just that.

  • How can I make my php.ini file recursive ?

Check the Extension Directory for PHP

It is also possible that the php.ini file is looking into an incorrect extension directory, especially if you just performed an update. Below are the instructions for adjusting the extensions directory in the php.ini file:

  1. Log into your account via SSH.
  2. Navigate to the /usr/local/lib/php/extensions directory.
  3. Run the following command on the directory:
    ls -lah

    You will then see all the extension directories inside.
    [email protected]#### [/usr/local/lib/php/extensions]# ls -lah drwxr-xr-x 5 root root 4.0K May 10  11:13 ./
     drwxr-xr-x 15 root root 4.0K Aug 28 2021 ../
     drwxr-xr-x 2 root root 4.0K Sep 2 2010 no-debug-non-zts-20060613/
     drwxr-xr-x 2 root root 4.0K May 10 11:48 no-debug-non-zts-20090626/
     drwxr-xr-x 2 root root 4.0K Oct 10 10:56 no-debug-non-zts-20100525/

  4. Check the dates to find the most recent one. Notate the full name of that directory. In our example it is no-debug-non-zts-20100525.
  5. Now you will need to open your php.ini file. Navigate to the home directory and open the file using nano.
    cd /home/public_html

    nano php.ini
  6. Once the file is opened, find the extension_dir setting and ensure that the path is the same as the latest one in your /usr/local/lib/php/extensions directory.
    ; Directory in which the loadable extensions (modules) reside.
     extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20100525"

Comment Out the extension_dir in php.ini

One additional option to the above fix is to simply comment the line for the extension_dir setting out in the php.ini. Doing this does no harm as it simply makes the php use the extension directory from the main server php.ini, which is most probably the one you want. To do so, simply place a semicolon (;) at the very beginning of the line as demonstrated below.

; Directory in which the loadable extensions (modules) reside.
 extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20100525"

Once you correct one or more of the above steps, you shoud no longer have any issues with the PDO error.

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

КОД:

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

Идеи, почему я получаю эту ошибку?

PHP 5.3.15
CloudLinux / CentOS 6
CPanel

42

Решение

пытаться

 yum install php-pdo
yum install php-pdo_mysql

service httpd restart

55

Другие решения

Попробуйте добавить use PDO; после вашего пространства имен или непосредственно перед вашим классом или в верхней части вашего PHP файл.

44

Это также может произойти, если есть php.ini файл в текущем рабочем каталоге веб-приложения. Если кто-то был помещен туда для изменения определенных настроек, он переопределит глобальный.

Чтобы избежать этой проблемы, не используйте php.ini файл для изменения настроек; вместо этого вы можете:

  • Укажите настройки в объявлении vhost
  • Используйте .htaccess файл с php_flag (посмотреть здесь)
  • Используйте .user.ini файл (посмотреть здесь)

21

Убедитесь, что они вызываются в файле php.ini

Если PDO отображается в списке установленных в настоящее время модулей php, вам нужно проверить файл php.ini в соответствующей папке, чтобы убедиться, что он вызывается. Где-то в файле php.ini вы должны увидеть следующее:

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

Если их нет, просто добавьте строки выше в конец файла php.ini и сохраните его.

11

Каков полный источник файла Mysql.php, Судя по выводу списка информации php, вы можете пытаться ссылаться на глобальный класс из пространства имен.

Если файл Mysql.php имеет выражение «пространство имен», используйте PDO на месте PDO — это скажет PHP искать глобальный класс, а не искать в локальном пространстве имен.

9

У меня была такая же проблема на GoDaddy. Я добавил extension=pdo.so в php.iniдо сих пор не работает. И только одна вещь пришла мне в голову: права доступа

Перед загрузкой файла убейте все процессы PHP (cPanel-> Процессы PHP).

Проблема заключалась в том, что с права доступа к файлу, было установлено 0644 и не был исполняемым. Вам нужно установить разрешение файла как минимум 0755,

права доступа

2

Я решил это с библиотекой PHP_PDO , потому что мой хостинг-провайдер не принял мое требование для установки драйвера PDO на сервер apache.

1

Эта ошибка вызвана PDO недоступно для PHP.

Если вы получаете сообщение об ошибке в командной строке или не через тот же интерфейс, который ваш веб-сайт использует для PHP, вы потенциально вызываете другую версию PHP или выдвигаете другую php.ini файл конфигурации при проверке phpinfo(),

Убедитесь, что PDO загружен, и драйверы PDO для вашей базы данных также загружены.

0

Понравилась статья? Поделить с друзьями:
  • Php fatal error class imagick not found
  • Pip install r requirements txt ошибка
  • Php fatal error cannot use object of type stdclass as array in
  • Pip install pycurl error windows
  • Php fatal error call to undefined function curl init