我似乎無法在用戶指南中找到明確的解釋。在CodeIgniter活動記錄中,爲了更新表格行,似乎需要做三件事:(1)識別要更新的記錄;(2)定義需要更改的記錄;(3)提交更改。請解釋CodeIgniter的ActiveRecord設置()更新()
不知何故,無論我如何閱讀手冊,目前尚不清楚。 http://ellislab.com/codeigniter/user-guide/database/active_record.html#update
它似乎意味着「設置」是關於插入 - 這意味着將行添加到我的書中的表。
「更新」是關於「改變」現有的信息。
對我而言,唯一的方法就是完成所有三項操作。
像這樣:
$this->db->where('id',$userid); //selecting the right user
$this->db->set($SubscriptionChoices); //setting the new values to be written
$this->db->update('userprefs'); //Do it. Update table userprefs
是的,但我的觀點是,我無法讓它工作。它一直抱怨我不得不使用「set()」。所以當你說' - > db-> where',然後' - > db-> update'時,我發現我必須使用' - > db-> where'然後' - > db-> set',然後使用' - > DB-> update'。這是我沒有得到的。 – Maxcot
上面的代碼工作。這聽起來像是你傳遞給update方法的數據數組有問題。嘗試一些簡單的測試。 – cartalot