1

I just recently upgraded my server's PHP version to 5.4.22, and now every script that uses PDO does not work.

An example of my PHP script which won't work:

<?php
    $dsn = 'mysql:dbname=testDB;host=127.0.0.1';
    $user = '[hidden]';
    $password = '[hidden]';
    try {
        $pdo = new PDO($dsn, $user, $password);

    } catch (PDOException $e) {
        echo 'Connection failed: ' . $e->getMessage();
        exit;
    }
?>

When i run the script i get: Fatal error: Class 'PDO' not found, i get this same error for every script that creates a connection.

I ran a check on puTTY to check PDO was even there and it found this:

root@cpanel [~]# php -m | grep -i pdo
PDO
pdo_mysql
pdo_sqlite

My php.ini has

extension=pdo.so
extension=pdo_sqlite.so
; sqlite was removed by EasyApache v3.22.24 on Sat Dec 14 23:24:10 2013 (PHP v5.4.x incompatibility)
; extension=sqlite.so
extension=pdo_mysql.so

phpinfo(); in PHP file claims im on PHP Version 5.3.10

How ever in my terminal # php -v says PHP 5.4.22

So this had really confused me why i'm getting two versions.

Sir
  • 8,135
  • 17
  • 83
  • 146
  • possible duplicate of [PHP Fatal error: Class 'PDO' not found](http://stackoverflow.com/questions/11813381/php-fatal-error-class-pdo-not-found) – Giacomo1968 Dec 15 '13 at 05:06
  • @JakeGould already read that question, didn't seem to help my situation =/ – Sir Dec 15 '13 at 05:07
  • do you see the line extension=pdo.so enabled in php.ini ? – Satya Dec 15 '13 at 05:09
  • Well I see `extension=pdo.so` it doesn't have enabled written next to it but it is there. – Sir Dec 15 '13 at 05:11
  • I meant , is it starting with ; ? – Satya Dec 15 '13 at 05:16
  • @Satya no it is not. the only one that is with ; is `; extension=sqlite.so` – Sir Dec 15 '13 at 05:17
  • I've noticed PDO is not in my phpinfo(); i don't know if that narrows down the possible causes of my issue? – Sir Dec 15 '13 at 05:27
  • What does `sqlite.so` have to do with `pdo_mysql.so`? – Giacomo1968 Dec 15 '13 at 05:29
  • @JakeGould where did i say it did? I merely pointed out it was only one with a semi colon. – Sir Dec 15 '13 at 05:30
  • Have you checked with `phpinfo();` in your actual PHP script? The command line PHP and the Apache module PHP are two different things. – Giacomo1968 Dec 15 '13 at 05:35
  • @JakeGould I checked `phpinfo();` in the PHP script it not only doesn't show `pdo` it shows my previous PHP version (which was the version that worked with my PDO at the time). Which is even more confusing. – Sir Dec 15 '13 at 05:37
  • @Dave Check my answer. It seems that your install of Apache still has the path for the old PHP module. Just find where to change the `LoadModule php5_module` in your setup & adjust it. All should be good. – Giacomo1968 Dec 15 '13 at 06:08

1 Answers1

1

Your question shows that you are checking the PHP version via the command line. But PHP via a web browser is going to use a module loaded into Apache which is a completely different thing. So check the output of phpinfo(); in a PHP script loaded via the web browser. Is PDO installed or shows as installed via that?

Wherever your Apache config files are look for the directory mods-available and the file php5.load. Under Ubuntu 12.04 it would be in this path:

/etc/apache2/mods-available/php5.load

And the contents should be:

LoadModule php5_module /usr/lib/apache2/modules/libphp5.so

Does the path in that file match where the newly compiled libphp5.so is installed?

Also, that LoadModule php5_module line could be a part of your main Apache configuration. Look around to find where that is set. And then just set the path of the new module to me wherever it’s actually installed.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103