Zend 框架 - 如果状态字段和 ID 匹配,我如何更新行?

Zend framework - how can i update the row if status field and id match?

如何仅在状态为 NULL 或完成或未完成且 ID 匹配时更新状态='ok'?

  $this->db->update('table1', 
                        array('status' => 'ok'), 
                        array('id=?' => 55));

为了进行比较,您不能对语句的 where 部分使用数组。相反,您应该使用 Where class.

在 .php 文件的顶部添加以下内容:

    use Zend\Db\Sql\Where;

那么你现在使用数组的地方你应该使用 Where 实例:

    $where = new Where();
    $where->equalTo('id', 55);
    $where->expression("( status IN('done','notdone') OR status IS NULL )", array() );
    $this->db->update('table1', 
                    array('status' => 'ok'), 
                    $where );