我如何将此PDO语句转换为CodeIgniter中的活动记录查询


How can i convert this PDO statement to active record query in CodeIgniter?

我有这个PDO语句工作得很好,但是我怎么能把它转换成CodeIgniter中的活动记录?

我的PDO语句是:

UPDATE mytable set total=bought+re_order-balance where retail_id=? and stock=? and stock_date=?

我试过了,但是没有用:

$data=array(                                                                                            
                    //some other fields
                    'total'=>'bought' + 're_order' - 'balance'                      
                    );
                $this->db->where('retail_id', $someid);
                $this->db->where('stock', $somestock);
                $this->db->where('stock_date', $somestock);
                $this->db->update('mytable',$data); 

当我尝试这个时,它没有同时给出任何错误,它没有更新数据库中的总字段。

下面的代码应该构建所需的查询。set()方法的第三个参数防止数据转义。您可以在文档

中阅读更多信息。
$this->db->set('total', 'bought + re_order - balance', FALSE)
            ->where('retail_id', $someid)
            ->where('stock', $somestock)
            ->where('stock_date', $somestock)
            ->update('mytable');