4

I am having a problem similar to https://stackoverflow.com/questions/2386575/the-pdo-extension-is-required-for-this-adapter-but-the-extension-is-not-loaded but not the same.

The Magento install is running fine but when I try to run:

require_once(APATH.MAGEPATH.'/app/Mage.php');
umask(0);
Mage::app();

in a directory outside of Magento I get the error:

Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with message 'The PDO extension is required for this adapter but the extension is not loaded' in
/home/inzana/public_html/Store/lib/Zend/Db/Adapter/Pdo/Abstract.php:342 
Stack trace: #0 /home/inzana/public_html/Store/lib/Zend/Db/Adapter/Abstract.php(247): Zend_Db_Adapter_Pdo_Abstract->setFetchMode(2) 
#1 /home/inzana/public_html/Store/app/code/core/Mage/Core/Model/Resource.php(165): Zend_Db_Adapter_Abstract->__construct(Array) 
#2 /home/inzana/public_html/Store/app/code/core/Mage/Core/Model/Resource.php(110): Mage_Core_Model_Resource->_newConnection('pdo_mysql', Object(Mage_Core_Model_Config_Element)) 
#3 /home/inzana/public_html/Store/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(320): Mage_Core_Model_Resource->getConnection('core_write') 
#4 /home/inzana/public_html/Store/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(350): Mage_Core_Model_Resource_Db_Abstract->_getConnection('write') 
#5 /home/inzana/public_html/Store/app/code/core/Mage/Core/Model/R in /home/inzana/public_html/Store/lib/Zend/Db/Adapter/Pdo/Abstract.php on line 342

I am running phpinfo(INFO_GENERAL); followed by the code that causes the error on this page: http://inzanaranch.com/test

The local php.ini file includes:

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

I am a loss of where to go next. Any help appreciated.

  • This is not a magento question, something with your configuration is really wrong. Are you sure that the domain and the subdir /test is from the same server? There seems to be no extension loaded on /test. This can't be afaik. – Fabian Blechschmidt Mar 14 '13 at 8:02
  • Yup, same server. I am going to try Alan's method as soon as I get back to that project. – Nate Bunney Mar 14 '13 at 20:45
4

When in doubt, add some temporary logging. There's something about your environment that's either turning PDO off, or there's a different PHP binary in your path when you're running it.

First, make sure you're using the PHP you think you are by running the following from the command line.

$ which php

This will tell you which PHP is in your path.

Next, open up lib/Zend/Db/Adapter/Pdo/Abstract.php and find the exception location

if (!extension_loaded('pdo')) {
    /**
     * @see Zend_Db_Adapter_Exception
     */
    #require_once 'Zend/Db/Adapter/Exception.php';
    throw new Zend_Db_Adapter_Exception('The PDO extension is required for this adapter but the extension is not loaded');
}

Then add some poor man's logging in front of the exception (Don't forget this is here, you'll want to remove this).

ob_start();
phpinfo();
echo "\n--------------------------------------------------\n";
print_r($_SERVER);
$message = ob_end_clean();
file_put_contents('/tmp/no-pdo.log',"\n",FILE_APPEND);

throw new Zend_Db_Adapter_Exception('The PDO extension is required for this adapter but the extension is not loaded');

Run your script.

Copy /tmp/no-pdo.log to your home directory, and then remove it and your logging code. The no-pdo.log will contain your PHP info at the time the error occurred. This will let you track down the problem — which is likely a rogue php.ini file.

| improve this answer | |
  • 1
    I am going to try this a little later today, thanks for this. If it works I will post the answer in the comments here and give you the check. Often an approach to debugging is much more valuable than an actual answer on something like this. – Nate Bunney Mar 14 '13 at 20:46
  • Yup, looks like a problem in the php.ini file. Now the question is what is blocking PDO in there... – Nate Bunney Mar 28 '13 at 0:59
  • I needed some changes to allow for larger uploads, but I do the same thing on all the sites on the server, so I went in and changed the default php.ini and that seems to have fixed everything. Thanks! – Nate Bunney Mar 28 '13 at 1:11
1

Checking pdo extension installed or not

echo 'Checking pdo extension installed or not';
echo '<pre/>';
extension_loaded ('PDO' ); // returns boolean

// or

extension_loaded('pdo_mysql');

// or get all extensions and search for a specific one

print_r(get_loaded_extensions());  exit();

If installed then show in print result array like below

[41] => PDO    [42] => pdo_sqlite    [43] => pdo_mysql
| improve this answer | |
0

Where are you calling require_once(APATH.MAGEPATH.'/app/Mage.php'); from?
Are you doing it as a different user?

Looking at the phpinfo() you posted, each user has their own php.ini - so I'm guessing wherever you are trying to include Mage.php from is using a different user, with a different php.ini that doesn't have the PDO extension loaded.

| improve this answer | |
  • I am not sure what you mean by a "different user". At the point where that link takes you no one is logged in. It is under the same user account on the linux system as the Magento store. I put a local php.ini file in the directory where this is being called from so I could control things directly and made sure everything in the php.ini from the Magento directory is set exactly the same in the local one. As you can see from the phpinfo output PDO is being reported as being part of the install. – Nate Bunney Mar 13 '13 at 18:06
  • Note the '-enable-pdo=shared' and '--with-pdo-mysql=shared' in the Configure Command section of the phpinfo. – Nate Bunney Mar 13 '13 at 18:09
  • Where are you calling require_once(APATH.MAGEPATH.'/app/Mage.php'); from? – Ben Lessani - Sonassi Mar 13 '13 at 19:08
  • We have magento set up in /Store on the account. We have a custom CMS that sits above that in / I am trying to call this from inside our custom CMS. Basically I have a controller that is creating an object from my Magento class and when we do that it is calling this code. – Nate Bunney Mar 13 '13 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.