尝试访问firebird时出现pdo异常

时间:2014-08-01 20:57:30

标签: php pdo zend-framework2 firebird firebird2.5

我必须使用php和zend framework 2访问firebird,并且我遇到以下错误:

 /var/www/html/cad/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Driver /Pdo/Statement.php:187

Message:

SQLSTATE[HY000]: General error: -204 Dynamic SQL Error SQL error code = -204 Table  unknown pessoa At line 1, column 19 

Stack trace:

#0 /var/www/html/cad/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Driver /Pdo/Statement.php(187): PDO->prepare('SELECT "pessoa"...')
#1 /var/www/html/cad/vendor/zendframework/zendframework/library/Zend/Db/Adapter/Driver/Pdo/Statement.php(213): Zend\Db\Adapter\Driver\Pdo\Statement->prepare()
#2 /var/www/html/cad/vendor/zendframework/zendframework/library/Zend/Db/TableGateway/AbstractTableGateway.php(233): Zend\Db\Adapter\Driver\Pdo\Statement->execute()
#3 /var/www/html/cad/vendor/zendframework/zendframework/library/Zend/Db/TableGateway/AbstractTableGateway.php(208): Zend\Db\TableGateway\AbstractTableGateway->executeSelect(Object(Zend\Db\Sql\Select))
#4 /var/www/html/cad/vendor/zendframework/zendframework/library/Zend/Db/TableGateway/AbstractTableGateway.php(195): Zend\Db\TableGateway\AbstractTableGateway->selectWith(Object(Zend\Db\Sql\Select))
#5 /var/www/html/cad/module/Pessoa/src/Pessoa/Model/PessoaTable.php(18): Zend\Db\TableGateway\AbstractTableGateway->select()
#6 /var/www/html/cad/module/Pessoa/src/Pessoa/Controller/PessoaController.php(26): Pessoa\Model\PessoaTable->fetchAll()
#7 /var/www/html/cad/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractActionController.php(83): Pessoa\Controller\PessoaController->indexAction()
#8 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#9 /var/www/html/cad/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#10 /var/www/html/cad/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#11 /var/www/html/cad/vendor/zendframework/zendframework/library/Zend/Mvc/Controller/AbstractController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#12 /var/www/html/cad/vendor/zendframework/zendframework/library/Zend/Mvc/DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#13 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#14 /var/www/html/cad/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#15 /var/www/html/cad/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#16 /var/www/html/cad/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(313): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#17 /var/www/html/cad/public/index.php(17): Zend\Mvc\Application->run()
#18 {main}

Global.php

return array(
 'db' => array(
     'driver'         => 'Pdo',
     'dsn'            => 'firebird:dbname=/opt/bancos/teste.fdb',   //array(PDO::ATTR_PERSISTENT => true),
     /*'driver_options' => array(
         PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
     ),*/
 ),
 'service_manager' => array(
     'factories' => array(
         'Zend\Db\Adapter\Adapter'
                 => 'Zend\Db\Adapter\AdapterServiceFactory',
     ),
 ),
 );
?>

local.php

<?php
return array(
    'db' => array(
            'username' => 'sysdba',
            'password' => 'masterkey',
    ),
);
?>

PessoaController.php

 public function indexAction()
 {

        return new ViewModel(array(
                'pessoas' => $this->getPessoaTable()->fetchAll(),
        ));


  }

PessoaTable.php

public function fetchAll()
 {
            try{
    $resultSet = $this->tableGateway->select();
            } catch(Exception $e){
              $e->getMessage();
            }
    return $resultSet;
  }

这是方法getPessoaTable()

public function getPessoaTable()
 {
    if (!$this->pessoaTable) {
        $sm = $this->getServiceLocator();
        $this->pessoaTable = $sm->get('Pessoa\Model\PessoaTable');
    }
    return $this->pessoaTable;
 }

我在php中配置了pdo_firebird.so。它出现在phpinfo()

1 个答案:

答案 0 :(得分:2)

错误的重要部分是:&#34;表未知的pessoa&#34; 。您正在从表pessoa中进行选择,根据Firebird,不存在此类表。错误消息中pessoa为小写的事实表明您使用的是带引号的标识符。带引号的标识符在Firebird中区分大小写。不带引号的标识符是大写的,以使它们不区分大小写。

所以这个错误要么意味着表格确实不存在,要么 - 当你使用带引号的标识符时 - 表名实际上是PESSOA。 Firebird用于引用/不带引号的标识符的规则将使SELECT ... FROM pessoa生效,但SELECT ... FROM "pessoa"失败。

我不了解PDO,所以我无法提供PDO特定的帮助,但我希望这能为您缩小范围。