此适配器需要 PDO 扩展,但未加载扩展

2021-12-29 00:00:00 php zend-framework apache2.2

当我尝试使用 Zend_Db_Table_Abstract 类的 fetchall 方法时,出现以下异常...

I am getting the following exception when i try to use the fetchall method of the Zend_Db_Table_Abstract class...

An error occurred4545
EXCEPTION_OTHER
Exception information:
Message: The PDO extension is required for this adapter but the extension is not loaded 

Stack trace:
#0 D:wwwTestProjectlibraryendDbAdapterPdoMysql.php(96): Zend_Db_Adapter_Pdo_Abstract->_connect()
#1 D:wwwTestProjectlibraryendDbAdapterAbstract.php(448): Zend_Db_Adapter_Pdo_Mysql->_connect()
#2 D:wwwTestProjectlibraryendDbAdapterPdoAbstract.php(238): Zend_Db_Adapter_Abstract->query('DESCRIBE `album...', Array)
#3 D:wwwTestProjectlibraryendDbAdapterPdoMysql.php(156): Zend_Db_Adapter_Pdo_Abstract->query('DESCRIBE `album...')
#4 D:wwwTestProjectlibraryendDbTableAbstract.php(823): Zend_Db_Adapter_Pdo_Mysql->describeTable('albums', NULL)
#5 D:wwwTestProjectlibraryendDbTableAbstract.php(862): Zend_Db_Table_Abstract->_setupMetadata()
#6 D:wwwTestProjectlibraryendDbTableAbstract.php(969): Zend_Db_Table_Abstract->_setupPrimaryKey()
#7 D:wwwTestProjectlibraryendDbTableSelect.php(100): Zend_Db_Table_Abstract->info()
#8 D:wwwTestProjectlibraryendDbTableSelect.php(78): Zend_Db_Table_Select->setTable(Object(Application_Model_Albums))
#9 D:wwwTestProjectlibraryendDbTableAbstract.php(1005): Zend_Db_Table_Select->__construct(Object(Application_Model_Albums))
#10 D:wwwTestProjectlibraryendDbTableAbstract.php(1303): Zend_Db_Table_Abstract->select()
#11 D:wwwTestProjectapplicationcontrollersIndexController.php(17): Zend_Db_Table_Abstract->fetchAll()
#12 D:wwwTestProjectlibraryendControllerAction.php(513): IndexController->indexAction()
#13 D:wwwTestProjectlibraryendControllerDispatcherStandard.php(289): Zend_Controller_Action->dispatch('indexAction')
#14 D:wwwTestProjectlibraryendControllerFront.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#15 D:wwwTestProjectlibraryendApplicationBootstrapBootstrap.php(97): Zend_Controller_Front->dispatch()
#16 D:wwwTestProjectlibraryendApplication.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#17 D:wwwTestProjectpublicindex.php(26): Zend_Application->run()
#18 {main}  
Request Parameters:
array (
  'controller' => 'index',
  'action' => 'index',
  'module' => 'default',
)  

我在php.ini文件中添加了以下几行

I have added the following lines in the php.ini file

extension=pdo.so
extension=pdo_mysql.so

extension=php_pdo.dll 
extension=php_pdo_mssql.dll 

我的系统中还安装了PDO MySQL 包.但我仍然收到上述异常......(还重新启动了Apache服务器)

Also i have The PDO MySQL package installed in my system. But still I am getting the above exception.... (Also restarted the Apache server)

推荐答案

首先,你不能同时拥有:

First of all, you cannot have both :

extension=pdo.so
extension=pdo_mysql.so

适用于 Linux,以及:

Which are for Linux, and :

extension=php_pdo.dll 
extension=php_pdo_mssql.dll 

哪些适用于 Windows:您必须选择,具体取决于您使用的系统.

Which are for windows : you've got to choose, depending on the system you are using.

在 Windows 上,您应该使用 .dll 版本.

As you are on windows, you should use the .dll version.


但请注意,您使用了 :


But note that you used :

extension=php_pdo_mssql.dll 

即您加载了 pdo_mssql 扩展——它用于 Microsoft SQL Server,而不是 MySQL.

i.e. you loaded the pdo_mssql extension -- which is for Microsoft SQL Server, and not MySQL.

相反,您应该加载 MySQL 的扩展:

Instead, you should load the extension for MySQL :

extension=php_pdo_mysql.dll 

更正后,重启Apache;情况应该会好转.

After correcting that, restart Apache ; and things should get better.


如果情况没有好转,您应该检查 phpinfo() 的输出:

  • phpinfo()输出的开头,表示加载的是哪个php.ini文件;确保你修改了正确的.
  • 检查,文件中是否有关于pdo_mysql的部分
    • 如果没有,请检查 Apache 的 error_log,以防万一;-)
    • At the beginning of phpinfo()'s output, it indicates which php.ini file is loaded ; make sure you modified the right one.
    • Check, lower in the file, if there is a section about pdo_mysql
      • If not, check Apache's error_log, just in case ;-)

相关文章