$this->db->where();
本函数允许你使用四种方法中的一种来设置 WHERE 子句: 说明: 传递给本函数的所有值都会被自动转义,以便生成安全的查询。
简单的 key/value 方法: $this->db->where('name', $name);
// 生成: WHERE name = 'Joe' 请注意等号已经为你添加。
如果你多次调用本函数,那么这些条件会被 AND 连接起来:
$this->db->where('name', $name);
$this->db->where('title', $title);
$this->db->where('status', $status);
// WHERE name = 'Joe' AND title = 'boss' AND status = 'active'
自定义 key/value 方法: 你可以在第一个参数中包含一个运算符,以便控制比较:
$this->db->where('name !=', $name);
$this->db->where('id <', $id);
// 生成: WHERE name != 'Joe' AND id < 45
关联数组方法: $array = array('name' => $name, 'title' => $title, 'status' => $status);
$this->db->where($array);
// 生成: WHERE name = 'Joe' AND title = 'boss' AND status = 'active' 使用这个方法时你也可以包含运算符:
$array = array('name !=' => $name, 'id <' => $id, 'date >' => $date);
$this->db->where($array);
自定义字符串: 你可以手动的编写子句:
$where = "name='Joe' AND status='boss' OR status='active'";
$this->db->where($where);