php 异常:如何包含有关有问题的 sql 查询的更多信息

发布于 2024-12-29 19:46:33 字数 2126 浏览 0 评论 0原文

好吧,这就像我第一千次从 php 异常中得到一些无用的信息。它总是看起来像这样:

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 /usr/share/php5/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#1 /usr/share/php5/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#2 /usr/share/php5/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('UPDATE `product...', Array)
#3 /usr/share/php5/Zend/Db/Adapter/Abstract.php(634): Zend_Db_Adapter_Pdo_Abstract->query('UPDATE `product...', Array)
#4 /usr/share/php5/Zend/Db/Table/Abstract.php(1132): Zend_Db_Adapter_Abstract->update('products', Array, 'shop = '1' AND ...')
#5 /var/www/simira/html/application/models/DbTable/Products.php(250): Zend_Db_Table_Abstract->update(Array, 'shop = '1' AND ...')
#6 /var/www/simira/html/application/controllers/ShopsController.php(567): Application_Model_DbTable_Products->updatePriceByShopCategories(Array, '1')
#7 /var/www/simira/html/application/controllers/ShopsController.php(597): ShopsController->processGlobalChangeRequest('Price', 'Products')
#8 /usr/share/php5/Zend/Controller/Action.php(516): ShopsController->globalChangePriceAction()
#9 /usr/share/php5/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('globalChangePri...')
#10 /usr/share/php5/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#11 /usr/share/php5/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#12 /usr/share/php5/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#13 /var/www/simira/html/public/index.php(29): Zend_Application->run()
#14 {main}

我现在真正需要看到的是查询。如何将此信息包含到引发的异常中?我可以这样做,以便查询不会在 query('UPDATE Product...', Array) 中被删除吗?我想知道是否有一个可以在全球范围内应用的解决方案。如果有帮助的话,我正在使用 Zend Framework。

Allright, this is like thousandth time when I get kinda useless information from a php exception. It always looks like this:

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 /usr/share/php5/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array)
#1 /usr/share/php5/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
#2 /usr/share/php5/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('UPDATE `product...', Array)
#3 /usr/share/php5/Zend/Db/Adapter/Abstract.php(634): Zend_Db_Adapter_Pdo_Abstract->query('UPDATE `product...', Array)
#4 /usr/share/php5/Zend/Db/Table/Abstract.php(1132): Zend_Db_Adapter_Abstract->update('products', Array, 'shop = '1' AND ...')
#5 /var/www/simira/html/application/models/DbTable/Products.php(250): Zend_Db_Table_Abstract->update(Array, 'shop = '1' AND ...')
#6 /var/www/simira/html/application/controllers/ShopsController.php(567): Application_Model_DbTable_Products->updatePriceByShopCategories(Array, '1')
#7 /var/www/simira/html/application/controllers/ShopsController.php(597): ShopsController->processGlobalChangeRequest('Price', 'Products')
#8 /usr/share/php5/Zend/Controller/Action.php(516): ShopsController->globalChangePriceAction()
#9 /usr/share/php5/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('globalChangePri...')
#10 /usr/share/php5/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#11 /usr/share/php5/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#12 /usr/share/php5/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#13 /var/www/simira/html/public/index.php(29): Zend_Application->run()
#14 {main}

What I really need to see now is the query. How can I include this information into an exception being thrown? Can I make it so that the query is not cut away in query('UPDATE product...', Array)? I'd like to know if there is a solution I can apply globally. I am on Zend Framework if that helps.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盛装女皇 2025-01-05 19:46:33

Zend Framework 包含一个很棒的数据库分析器界面。

我个人最喜欢的是 FirePHP 实现。这会在 Firebug 控制台中显示完整的查询信息。

请参阅 http://framework。 zend.com/manual/en/zend.db.profiler.html#zend.db.profiler.profilers.firebug

您还可以启用 MySQL 查询日志记录。请参阅http://dev.mysql.com/doc/refman/ 5.5/en/query-log.html

Zend Framework includes an awesome DB profiler interface.

My personal favourite is the FirePHP implementation. This shows complete query information in your Firebug console.

See http://framework.zend.com/manual/en/zend.db.profiler.html#zend.db.profiler.profilers.firebug

You can also enable MySQL query logging. See http://dev.mysql.com/doc/refman/5.5/en/query-log.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文