CI搜索$this>db>where()
1. 简单的 key/value 方式:
$this->db->where("name",$name);// Produces: WHERE name = "Joe"
注意自动为你加上了等号。
如果你多次调用该方法,那么多个 WHERE 条件将会使用 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"
2. 自定义 key/value 方式:
为了控制比较,你可以在第一个参数中包含一个比较运算符:
$this->db->where("name !=",$name);$this->db->where("id <",$id);// Produces: WHERE name != "Joe" AND id < 45
3. 关联数组方式:
$array = array("name" => $name,"title" => $title,"status" => $status);$this->db->where($array);
// Produces: WHERE name = "Joe" AND title = "boss" AND status = "active"
你也可以在这个方法里包含你自己的比较运算符:
$array = array("name !=" => $name,"id <" => $id,"date >" => $date);$this->db->where($array);
4. 自定义字符串:
你可以完全手工编写
WHERE
子句:
$where = "name="Joe" AND status="boss" OR status="active"";$this->db->where($where);
$this->db->where() 方法有一个可选的第三个参数,如果设置为 FALSE,CodeIgniter 将不保护你的表名和字段名。
$this->db->where("MATCH (field) AGAINST ("value")", NULL, FALSE);
以上是 CI搜索$this>db>where() 的全部内容, 来源链接: utcz.com/z/532123.html