[英]How do I convert this SQL query to Codeigniter Active Record?
[英]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');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.