gpt4 book ai didi

php - Zend PDO 错误 - 我该如何调试它?

转载 作者:可可西里 更新时间:2023-11-01 07:08:32 25 4
gpt4 key购买 nike

我在使用 Zend Framework 和 Mysql 时遇到了一个奇怪的问题。我生成了一个查询:

SELECT events.idUser, szForename, szLastname, readers.szName, idZoneFrom, events.dtTime FROM events, users, readers WHERE events.idUser = users.idUser AND events.idReader = readers.idReader AND dtTime >= '2010:02:15 0:00:00' AND dtTime < '2010:02:16 0:00:00' ORDER BY dtTime

如果我在某些控制台(如 pma、navicat 或 shell 客户端)中运行它,查询工作正常,但是当我尝试使用通过 commend 扩展 Zend_Db_Table 的模型运行它时

$arResult = $this->getDefaultAdapter()->query($szQuery)->fetchAll();

出现 1064 错误:

enter code here

An error occurred
Application error
Exception information:

Message: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Stack trace:

#0 C:\xampp\htdocs\projekty\doors2\library\Zend\Db\Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#1 C:\xampp\htdocs\projekty\doors2\library\Zend\Db\Adapter\Abstract.php(468): Zend_Db_Statement->execute(Array)
#2 C:\xampp\htdocs\projekty\doors2\library\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query('SELECT zoneName...', Array)
#3 C:\xampp\htdocs\projekty\doors2\application\models\Zones.php(24): Zend_Db_Adapter_Pdo_Abstract->query('SELECT zoneName...')
#4 C:\xampp\htdocs\projekty\doors2\application\models\Events.php(87): Application_Model_Zones->getZoneInfo(NULL)
#5 C:\xampp\htdocs\projekty\doors2\application\controllers\IndexController.php(52): Application_Model_Events->getEventsList(NULL, '02/15/2010')
#6 C:\xampp\htdocs\projekty\doors2\library\Zend\Controller\Action.php(513): IndexController->eventsAction()
#7 C:\xampp\htdocs\projekty\doors2\library\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('eventsAction')
#8 C:\xampp\htdocs\projekty\doors2\library\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#9 C:\xampp\htdocs\projekty\doors2\library\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#10 C:\xampp\htdocs\projekty\doors2\library\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#11 C:\xampp\htdocs\projekty\doors2\public\index.php(26): Zend_Application->run()
#12 {main}

Request Parameters:

array (
'controller' => 'index',
'action' => 'events',
'module' => 'default',
'idUser' => '0',
'dt' => '02/15/2010',
)

如何调试才能发现问题??或者也许你知道我做错了什么?

附言。我使用同一个数据库用户进行 php 和查询测试...

最佳答案

正如我所见,您的 SQL 语句有保留字。您应该尝试建立自己的连接,以便它可以自动转义标识符,或者您应该自己手动完成。对于第一个选项,试试这个:

  $options = array(Zend_Db::AUTO_QUOTE_IDENTIFIERS => false);
$params = array(
'host' => 'host',
'username' => 'user',
'password' => 'secret',
'dbname' => 'db',
'options' => $options
);
$db = Zend_Db::factory('Pdo_Mysql', $params);

关于php - Zend PDO 错误 - 我该如何调试它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3483941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com