CodeIgniter 操作数据库
涉及到数据库,就是比较复杂的内容了,所以本文略长,但是CI还是为我们省了很多麻烦事。CI提供了强大的数据库函数类——Active Record,源码是/system/database/DB_active_rec.php文件。
#使用
$this -> db -> 方法名()
#连接数据库
$this -> db -> 方法名();
#插入
$this -> db -> insert(表名, 数据);
#更新
$this -> db -> where(字段名, 字段值);
$this -> db -> update(表名, 修改值的数组);
#查找
$this -> db -> where(字段名, 字段值);
$this -> db -> select(查找的字段名);
$query = $this -> db -> get(表名);
return $query -> result();
#删除
$this -> db -> where(字段名, 字段值);
$this -> db -> delete(表名);
参考资料: