以下程式碼是根據CodeIgniter_2.1.3版
用PHP向資料庫中實作簡單的增刪改查(純程式碼)請戳
http://www.cnblogs.com/corvoh/p/4641476.html 1.3與PHP5.6的相容問題請戳
http://www.cnblogs.com/corvoh/p/4649357.html
增:
<span>//</span><span>insert<br></span><span><span>//语法:$bool=$this->db->insert('表名',关联数组);<br></span></span><span>$data</span>=<span>array</span><span>( </span> 'username'=>'mary', 'password'=>'mary',<span>//建立一个用户名叫mary,密码为mary的数组,并传递给变量$data</span><span>); </span><span>$bool</span>=<span>$this</span>->db->insert('user',<span>$data</span><span>);<span>//将$data插入数据库的user表中</span></span><span>var_dump</span>(<span>$bool</span>);<span>//成功则返回TURE</span>
<span>//</span><span>delete<br>//语法:<span>$bool=$this->db->delete('表名',WHERE条件);</span></span><span>$bool</span>=<span>$this</span>->db->delete('user',<span>array</span>('id'=>3<span>));<span>//删除数据库.user表里id=3的用户所有信息</span></span><span>var_dump</span>(<span>$bool</span>);<span>//成功则返回TURE</span>
<span>//<span>update <span>$data=<span>array<span>( 'password'=>12345,<span>); <span>$bool=<span>$this->db->update('user',<span>$data,<span>array('id'=>3<span>));<span>//将数据库.user表里id=3的用户密码给为12345<br></span><span>var_dump(<span>$bool);<span>//成功则返回TURE</span></span></span></span></span></span></span></span></span></span></span></span></span></span>
以上就介紹了用CI框架向資料庫中實現簡單的增刪改查,包括了方面的內容,希望對PHP教程有興趣的朋友有所幫助。