codeigniter custom where子句中的错误
问题描述:
I'm referring the codeigniter user guide to write a custom where clause. as per the guide it says for custom where clauses write like this.
$where = "name='Joe' AND status='boss' OR status='active'";
$this->db->where($where);
but when i use in my model browser is throwing an error.
A Database Error Occurred
Error Number: 1054
Unknown column 'user_name='Joe'' in 'where clause'
SELECT * FROM (`Management`) WHERE `user_name='Joe'` AND password='boss' OR password='active'
Filename: /var/www/models/hr_login_model.php
Line Number: 28
this is just a testing query. my actual query is dynamic one and it is also giving this error.
$where = "user_name='".$username."' AND password='".$password."' AND Department='".$dep_br."' OR Br_no='".$dep_br."'";
why it always taking the column name and the value, both as a column name?
我在引用codeigniter用户指南来编写自定义where子句。 as根据指南它说自定义where子句这样写。 p>
$ where =“name ='Joe'AND status ='boss'OR status ='active'”;
$ this-> db-> where( $其中);
code> pre>
但是当我在我的模型浏览器中使用时会抛出错误。 p>
发生数据库错误
错误号码:1054
未知列'user_name ='Joe''在'where子句'
SELECT * FROM(`Management`)WHERE`user_name ='Joe'`和password ='boss'或密码= 'active'
文件名:/var/www/models/hr_login_model.php
nnnLine Number:28
code> pre>
这只是一个测试查询。 我的实际查询是动态查询,它也会出现此错误。 p>
$ where =“user_name ='”。$ username。“'AND password ='”。$ password 。“'AND = =”。$ dep_br。“'或者Br_no ='”。$ dep_br。“'”;
code> pre>
为什么它总是采取列 名称和值,都作为列名? p>
div>
答
use following
$where = "user_name='$username' AND password='$password' AND (Department='$dep_br' OR Br_no='$dep_br')";
答
User space befor and after = like shown below.
$where = "name = 'Joe' AND status = 'boss' OR status = 'active'";
$this->db->where($where);
答
Try this:
$where = "name='Joe' AND status='boss' OR status='active'";
$this->db->where($where, NULL, FALSE);
答
Try this way it is much more better and secure
$this->db->where("name","joe");
$this->db->where("status =","boss");
$this->db->or_where("status","active");