Zend_Db_Table - 更新不起作用
该代码似乎不起作用。
// $counter is an instance of Zend_Db_Table_Abstract
$counter->update(array('hits' => 'hits+1'), '"id" = 1');
我查看了数据库分析器并发现以下查询:
UPDATE `downloads` SET `hits` = ? WHERE ("id" = 1)
The code seems not working.
// $counter is an instance of Zend_Db_Table_Abstract
$counter->update(array('hits' => 'hits+1'), '"id" = 1');
I took a look into the DB profiler and find the following query:
UPDATE `downloads` SET `hits` = ? WHERE ("id" = 1)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用 Zend_Db_Expr 的实例(一个 SQL 表达式)来使其工作(未经测试):
...或我认为应该工作的类似内容。如果不起作用请报告,我会给出经过测试的答案。
更新:
好的,我测试了它,它可以工作,前提是您在 where 子句中松开
id
周围的引号。id
不应被解释为文字字符串,而应被解释为列名称。也许您想改用反引号?就像这样 '`id` = 1'。这是引用 MySQL 标识符的正确方法。You need to use an instance of
Zend_Db_Expr
(an SQL expression) to get this to work (untested):... or something similar I believe should work. Report back if it doesn't work, and I'll come up with a tested answer.
UPDATE:
Ok, I tested it, and it works, provided that you loose the quotes around
id
in the where clause.id
shouldn't be interpreted as a literal string but as a column name. Maybe you ment to use backticks in stead? Like so '`id` = 1'. That is the proper way to quote an identifier for MySQL.