[英]Update with Zend_DB on multiple rows
我正在使用Zend Framework。 我有树表。 用户和组以及一个链接它们的表。
我想增加给定组用户的字段。 要增加一个用户,我要做:
$table = 'users';
$update = array(
'ACLVersion' => new Zend_Db_Expr('ACLVersion + 1')
);
$where[] = $db->quoteInto('id = ?', $user);
$db->update($table, $update, $where);
我尝试使用多个位置。
我不知道如何在Zend的某个地方加入表格。
要将JOIN
与Zend_Db_Table
,必须禁用完整性检查。
请参阅《 ZF参考指南》中的Zend_Db_Table
示例#27:
$table = new Bugs();
// retrieve with from part set, important when joining
$select = $table->select(Zend_Db_Table::SELECT_WITH_FROM_PART);
$select->setIntegrityCheck(false)
->where('bug_status = ?', 'NEW')
->join('accounts', 'accounts.account_name = bugs.reported_by')
->where('accounts.account_name = ?', 'Bob');
$rows = $table->fetchAll($select);
请注意,禁用完整性检查还将禁用生成的记录集的某些自动功能:
结果行或行集将作为“锁定”行返回(这意味着save(),delete()和任何字段设置方法将引发异常)。
使用给定组的ID数组加载$ num
以下代码将完成这项工作
$table = 'users';
$update = array(
'ACLVersion' => new Zend_Db_Expr('ACLVersion + 1')
);
$where = $db->quoteInto('id IN (?)', $num);
$db->update($table, $update, $where);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.