Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Fatal error: Class 'PDO' not found

Tags:

php

pdo

I have this PHP function which has been working very well until i reinstalled my dev system:

function connectDB($database, $username, $password) {

    $DSN = "mysql:host=localhost;dbname=$database";

    try {
        $DBH = new PDO($DSN, $username, $password); <--- LINE 10
        return $DBH;
    }
    catch(PDOException $e) {
        die("Could not connect to the database.\n");
    }
}

And i'm getting the error:

PHP Fatal error:  Class 'PDO' not found in /var/www/im/tools.php on line 10

I checked phpinfo() and PDO is enabled:

PDO drivers : mysql

PDO Driver for MySQL version: 5.1.54

The interesting thing is that the interaction with th MYSQL database is ok, but i'm still getting the error when debugging.

I'm puzzled about this error! My system is Ubuntu 11.04 + NGINX + PHP 5.3

Any tip to get rid of it? Thanks!

like image 462
Gabriel Avatar asked May 16 '11 03:05

Gabriel


People also ask

How do I install PDO drivers?

Pdo ( Portable Data Object ) needs to be installed if it is not done before. For windows platform go to control panel > Add remove program ( or Programs and features ) > Select your PHP installation and click Change. If you are installing PHP fresh then in the setup wizard you can select PDO from Extensions link.

What do you mean by PDO?

Protected Denomination of Origin: a geographical indication defined within European Union law in order to protect regional agricultural products and foodstuffs. Collins English Dictionary. Copyright © HarperCollins Publishers.


2 Answers

Are you using namespaced code? Maybe you need to use \PDO class then?

like image 95
Tomasz Kowalczyk Avatar answered Sep 24 '22 06:09

Tomasz Kowalczyk


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 change settings; instead, do this in the vhost declaration or a .htaccess file with 'php_flag'.

See also PHP Fatal error: Class 'PDO' not found

like image 23
Alastair Irvine Avatar answered Sep 24 '22 06:09

Alastair Irvine