Zend DB更新中的OR子句?

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)

dre*_*010 8

调用时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)