Zend_Db_Table_Abstract::update() 可能的错误
我有这段代码
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$users_table = new Application_Model_UserModel();
$result = $users_table->update(array(
"confirmed" => 1,
"key" => null
), array(
$db->quoteInto("'type' = ?", Application_Model_UserModel::TYPE_AWATAG),
"'confirmed' = 0",
$db->quoteInto("'id' = ?", $id),
$db->quoteInto("'key' = ?", $key)
));
// no record updated
if ($result == 0) {
throw new Zend_Exception("User not found.");
}
抛出异常(即:用户记录尚未更新),即使所有条件都正确。
是一个错误吗?您看到任何错误吗?
解决方案
我取消引用所有列名称并以这种方式添加表引用:
tablename.columnname = newvalue
感谢您的观看:)
I have this code
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$users_table = new Application_Model_UserModel();
$result = $users_table->update(array(
"confirmed" => 1,
"key" => null
), array(
$db->quoteInto("'type' = ?", Application_Model_UserModel::TYPE_AWATAG),
"'confirmed' = 0",
$db->quoteInto("'id' = ?", $id),
$db->quoteInto("'key' = ?", $key)
));
// no record updated
if ($result == 0) {
throw new Zend_Exception("User not found.");
}
that throws the exception (ie: the user record has not been updated), even that all the where conditions are correct.
Is a bug? Do you see any error?
Solution
I unquoted all columns name and added table reference in this way:
tablename.columnname = newvalue
Thanks for watching :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你想做什么?
您的
Application_Model_UserModel
必须扩展Zend_Db_Table_Abstract
。请参阅 http://framework.zend。 com/manual/en/zend.db.table.html#zend.db.table.defining
请记住在
$_name
中添加表名称。快速入门中的一些代码
现在,当您更新时,传递 $data ,它是一个关联数组,其键作为表中的字段,然后是 where 子句。
这不是 zend-framework 的错误。
What are you trying to do ?
Your
Application_Model_UserModel
must extendZend_Db_Table_Abstract
.See http://framework.zend.com/manual/en/zend.db.table.html#zend.db.table.defining
Please remember to add the table name in the
$_name
.A bit of code from quick start
Now when you are updating pass $data which is an associative array with the key as the fields in the table, and second the where clause.
This is not a bug with zend-framework.