Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database Zend框架:Get";无效的连接选项";适配器“;连接到PostgreSQL数据库时出错_Database_Zend Framework_Postgresql_Connection - Fatal编程技术网

Database Zend框架:Get";无效的连接选项";适配器“;连接到PostgreSQL数据库时出错

Database Zend框架:Get";无效的连接选项";适配器“;连接到PostgreSQL数据库时出错,database,zend-framework,postgresql,connection,Database,Zend Framework,Postgresql,Connection,我有一个奇怪的问题,我甚至在网上找不到太多答案 代码如下所示: $config = new Zend_Config_Ini('../application/configs/application.ini', APPLICATION_ENV); $db = Zend_Db::factory($config->resources->db->adapter, $config-&g

我有一个奇怪的问题,我甚至在网上找不到太多答案

代码如下所示:

$config = new Zend_Config_Ini('../application/configs/application.ini',
                              APPLICATION_ENV);
$db = Zend_Db::factory($config->resources->db->adapter,
                       $config->resources->db->params->toArray());
$db->setFetchMode(Zend_db::FETCH_ASSOC);
$db->query('set names utf8;');
然后我在屏幕上看到错误:

An error occurred
Application error
Exception information:

Message: SQLSTATE[08006] [7] invalid connection option "adapter"
Stack trace:

#0 /srv/uhg/ZF/library/Zend/Db/Adapter/Pdo/Pgsql.php(87): Zend_Db_Adapter_Pdo_Abstract->_connect()
#1 /srv/uhg/ZF/library/Zend/Db/Adapter/Abstract.php(459): Zend_Db_Adapter_Pdo_Pgsql->_connect()
#2 /srv/uhg/ZF/library/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('set names utf8;', Array)
#3 /srv/uhg/workspaces/zpe/library/Tls/Acl.php(72): Zend_Db_Adapter_Pdo_Abstract->query('set names utf8;')
#4 /srv/uhg/workspaces/zpe/application/controllers/IndexController.php(12): Tls_Acl->__construct('developer')
#5 /srv/uhg/ZF/library/Zend/Controller/Action.php(133): IndexController->init()
#6 /srv/uhg/ZF/library/Zend/Controller/Dispatcher/Standard.php(268): Zend_Controller_Action->__construct(Object(Zend_Controller_Request_Http ), Object(Zend_Controller_Response_Http), Array)
#7 /srv/uhg/ZF/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#8 /srv/uhg/ZF/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#9 /srv/uhg/ZF/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#10 /srv/uhg/workspaces/zpe/public/index.php(29): Zend_Application->run()
我还试图省略$config中的内容:

PDO_PGSQL:配置的东西

Array ( [adapter] => PDO_PGSQL
        [host] => localhost 
        [username] => postgres
        [password] =>
        [dbname] => uhg
        [default] => 1 )
当我在网上搜索这个时,有人建议我应该取消设置
$config->resources->db->adapter
(当然是在将它的值存储到某个地方之后),但当我尝试这样做时,它建议我不能

这似乎只发生在postgresql中,因为它可以很好地处理MySQL数据库

我对Posgresql很陌生,这可能是Postgresql的问题吗

请有人点灯

干杯

附言:

对于$db,它导出(我将真实的db名称替换为xx xxx):

对象(Zend_Db_Adapter_Pdo_Pgsql){91(12){[“{u pdoType”:protected]=>string(5)“Pgsql”[“[u numericDataTypes”:protected]=>array(12){[0]=>int(0)[1]=>int(1)[2]=>int(2)[“整数”]=>int(0)[“串行”]=>int(0)[“SMALLINT”]=>int(0)][BIGINT”]=>int(0)[>int(1)[BIGSERIAL 1]>int(1)=>int)[2]双十进制”](2) [“REAL”]=>int(2)}[“\u defaultStmtClass”:protected]=>string(21)“Zend\u Db\u Statement\u Pdo”[“\u config”:protected]=>array(10){[“adapter”]=>string(9)“Pdo\u Pgsql”[“host”]=>string(9)“localhost”[“username”]=>string(8)“postgres”[“password”]=>string(0)”“[“dbname”=>string(3)“xxx”[“default”=>string(1)”空字符集]=>[“persistent”]=>bool(false)[“options”]=>array(3){[“casebolding”]=>int(0)[“autoQuoteIdentifiers”]=>bool(true)[“fetchMode”]=>int(2)}[“driver”\u options”]=>array(0){}[“fetchMode”:profiler]=>int(2)[“profiler”:profiler”:protected=>object(Zend\u Db\profiler)=>object(false)[“\u FilterLapsedSecs”:protected]=>NULL[“\u filterTypes”:protected]=>NULL}[“\u defaultProfilerClass”:protected]=>string(16)“Zend\u Db\u Profiler”[“\u connection”:protected]=>NULL[“\u caseFolding”:protected]=>int(0)[“\u autoQuoteIdentifiers”:protected]=>bool(真)[“\u allowSerialization]=>bool(真)[\u AutoReconnected)]“:protected]=>bool(false)}

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

谢谢大家的帮助,我找到了一个解决方法:

$db = new Zend_Db_Adapter_Pdo_Pgsql(array(
             'host' => 'localhost',  
            'username' => 'postgres',  
            'password' => '',  
            'dbname' => 'uhg'        
 ));

我想我能看到发生了什么,但如何或为什么还不清楚


“adapter”选项似乎被传递给PostgreSQL连接本身,显然它不支持这一点。

适配器名称的正确参数是“Pdo_Pgsql”。您还可以显示
$config->resources->db
中的内容吗(当然可以屏蔽任何敏感信息)?@MIlen,您好,似乎即使我按照您建议的方式更改了适配器名称,它也不会改变任何东西。@MIlen,对于$config->resources->db,它导出一个对象:我将把它粘贴到上面的问题帖子中。Offtopic:“set names utf8;”不是有效的PostgreSQL查询,它将失败。请使用“set client\u encoding=utf8;”如果默认设置不合适,请为当前会话设置正确的编码。如果您找到了解决方案,我认为您应该添加自己的答案并接受它。