Strange PDO error

Hi guys

i have two pdo connection file as follows

  1. public_html/includes/pdo_connection.php
  2. public_html/new_system/includes/pdo_connection.php

both of the pdo_connection.php files are identical.
problem is first works, but not the second one.

Fatal error: Class ‘PDO’ not found in /home/fazihuz3/public_html/fazihuzzamaan.tk/includes/pdo_connection.php on line 13

What could be wrong? i have put the file contents below .

<?php 
 
/*** mysql hostname ***/ 
$hostname = 'localhost'; 
 
/*** mysql username ***/ 
$username = 'fazihuz3_zamaan'; 
 
/*** mysql password ***/ 
$password = 'some_password'; 
 
try { 
    $db = new PDO("mysql:host=$hostname;dbname=fazihuz3_stats", $username, $password); 
    /*** echo a message saying we have connected ***/ 
    //echo 'Connected to database';  
        
    // Throw exceptions on errors 
    $db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); 
     
    // Use assoc arrays by default 
    $db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC);         
 
    array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET time_zone = \'+03:00\'')    ; 
    array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"); 
}catch(PDOException $e){ 
    echo $e->getMessage(); 
} 
 
//this is a must for saving and retrving utf-8 (arabic) charactors to db// 
$query = $db->query("SET NAMES 'utf8'"); 
$query->execute(); 
 
 
?>

This error has nothing to do with your code. PDO is a built-in PHP class and in case it is not found, it is not configured for your new system web-server. It should be enabled in php.ini. To verify, you can run phpinfo() in your new system and see if you can find PDO mentioned on the page.

The only other possibility is that your new system is using namespaces and in this case you should address PDO as \PDO.

1 Like

HI colshrapnel,

i just did a phpinfo on that dir and i can see these

Configure Command :

‘–enable-pdo=shared’
‘–with-pdo-mysql=shared’
‘–with-pdo-sqlite=shared’

Thank you

i also got some apache error log when running the script having the pdo connection.

Fri Sep 23 04:14:38 2016] [error] [client xxx.xxx.xxx.xxx.] Cannot load the ionCube PHP Loader - it was built with configuration API220090626,NTS, whereas running engine is API220100525,NTS, referer: http://example.com/content/login/login_form.php
[Fri Sep 23 04:14:38 2016] [error] [client xxx.xxx.xxx.xxx.] Zend Guard Loader requires Zend Engine API version 220090626., referer: http://example.com/content/login/login_form.php
[Fri Sep 23 04:14:38 2016] [error] [client xxx.xxx.xxx.xxx.] The Zend Engine API version 220100525 which is installed, is newer., referer: http://example.com/content/login/login_form.php
[Fri Sep 23 04:14:38 2016] [error] [client xxx.xxx.xxx.xxx.] Contact Zend Technologies at http://www.zend.com/ for a later version of Zend Guard Loader., referer: http://example.com/content/login/login_form.php
[Fri Sep 23 04:14:38 2016] [error] [client xxx.xxx.xxx.xxx.] , referer: http://example.com/content/login/login_form.php

Open up your php.ini file and search for:

extension=php_pdo_mysql.dll

If there’s a ; at the start of that line, remove the ; then save the changes. You’ll then need to restart the server for the changes to take affect

1 Like

Hi buddy,

Thank you for the tip. but mean time my managed server provider had managed to solve the issue. this is what they said.

The issue has now been resolved.

On checking, I could see that you have been using some custom setup to
load PHP config files from the location
/var/lib/php/liberal/fazihuz3/php.ini which did not have PDO class
listed in its modules and this is why you ended up in the error.

I renamed the location so that the default PHP configs are loaded from /usr/local/lib/php.ini.

Thank you every for the replies. really appreciate it…

This worked and the sites display the PDO connection just fine. :slight_smile:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.