Sir
Sir

Reputation: 8280

PDO will not run since upgrading PHP to 5.4.22

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.

Upvotes: 1

Views: 2803

Answers (1)

Giacomo1968
Giacomo1968

Reputation: 26066

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.

Upvotes: 1

Related Questions