joe*_*t45 5 zend-framework zend-db-table zend-db
我想用OR子句进行Zend db更新.什么是相同的声明:
UPDATE mail
SET message_read = 1
WHERE id = 5
OR id = 10
Run Code Online (Sandbox Code Playgroud)
调用时Zend_Db_Adapter::update()
,WHERE
将使用AND
(函数_whereExpr中的Zend/Db/Adapter/Abstract.php的第698行)自动组合多个条件.
您可以通过创建自己的Zend_Db_Expr
作为WHERE
条件来解决这个问题,并且不会受到影响.
例如:
$where[] = new Zend_Db_Expr(
$table->getAdapter()->quoteInto('id = ?', 5) . ' OR ' .
$table->getAdapter()->quoteInto('id = ?', 10)
);
// resulting expression:
// WHERE (id = 5 OR id = 10)
$table->update($data, $where);
Run Code Online (Sandbox Code Playgroud)
如果您有其他WHERE
条件,他们将与OR
条件相结合AND
.
例:
$where[] = new Zend_Db_Expr(
$table->getAdapter()->quoteInto('id = ?', 5) . ' OR ' .
$table->getAdapter()->quoteInto('id = ?', 10)
);
$where[] = $table->getAdapter()->quoteInto('type = ?', 'sometype');
// resulting expression:
// WHERE (id = 5 OR id = 10) AND (type = 'sometype')
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1756 次 |
最近记录: |