Zend pgsql连接错误

时间:2014-06-18 07:16:27

标签: php mysql postgresql zend-framework zend-framework2

使用zend和pgsql连接时出现以下错误 早些时候我的程序在mysql工作正常

Array ( [host]     => localhost 
        [username] => openerp 
        [password] => postgresql 
        [dbname]   => projects_display 
        [adapter]  => PDO_PGSQL ) 
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[08006] [7] invalid connection option "adapter"' in /var/www/projects/display/display_res/library/Zend/Db/Adapter/Pdo/Abstract.php:129 
Stack trace: 
#0 /var/www/projects/display/display_res/library/Zend/Db/Adapter/Pdo/Abstract.php(129): PDO->__construct('pgsql:host=loca...', 'openerp', 'postgresql', Array) 
#1 /var/www/projects/display/display_res/library/Zend/Db/Adapter/Pdo/Pgsql.php(87): Zend_Db_Adapter_Pdo_Abstract->_connect() 
#2 /var/www/projects/display/display_res/library/Zend/Db/Adapter/Abstract.php(860): Zend_Db_Adapter_Pdo_Pgsql->_connect() 
#3 /var/www/projects/display/display_res/library/Zend/Db/Adapter/Pdo/Pgsql.php(171): Zend_Db_Adapter_Abstract->quote('tbl_user_groups') 
#4 /var/www/projects/display/display_res/library/Zend/Db/Table/Abstract.php(835): Zend_Db_Adapter_Pdo_Pgsql->describeTable('tbl_user_groups', NULL) 
#5 /var/www/projects/display/display_res/library/Zend/Db/Table/Abstract.php(874): Zend_Db_Table_Abstract->_setupMetadata() 
#6 /var in /var/www/projects/display/display_res/library/Zend/Db/Adapter/Pdo/Abstract.php on l
protected function _initDb()
{

    $config = $this->getOptions();

    //print_r($config);
    // db stuff here
    $parameters =array(
        'host'     => $config['resources']['db']['params']['host'],
        'username' => $config['resources']['db']['params']['username'],
        'password' => $config['resources']['db']['params']['password'],
        'dbname'   => $config['resources']['db']['params']['dbname'],
        'adapter'  => $config['resources']['db']['adapter']
    );
    print_r($parameters);
    echo "<br>";
    try {
        $db = Zend_Db::factory($config['resources']['db']['adapter'], $parameters);
        $db->getConnection();
    } catch (Zend_Db_Adapter_Exception $e) {

    } catch (Zend_Exception $e) { 
    }
    Zend_Db_Table::setDefaultAdapter($db);


}

1 个答案:

答案 0 :(得分:1)

在将数组作为第二个参数传递给$parameters['adapter']之前删除Zend_Db::factory

...
try {
    unset($parameters['adapter']);
    $db = Zend_Db::factory($config['resources']['db']['adapter'], $parameters);
    $db->getConnection();
}
...