我试图使用自定义字符串选择一些值.下面是我的代码
$this->db->from('posted');
$st="infor='rent' AND (typeq='in' OR typeq='out')";
$this->db->where($st);
$q = $this->db->get();
Run Code Online (Sandbox Code Playgroud)
发生数据库错误
Run Code Online (Sandbox Code Playgroud)Error Number: 1054 Unknown column ‘infor=‘rent’’ in ‘where clause’ SELECT * FROM (`posted_ads`) WHERE `infor=‘rent’` AND (typeq=‘in’ OR typeq=‘out’) Filename: C:\wamp\www\parklot\system\database\DB_driver.php Line Number: 330
我认为问题是因为
WHERE `infor='rent'`
Run Code Online (Sandbox Code Playgroud)
当我manualy执行此代码时,它完美地工作.
WHERE infor='rent'
Run Code Online (Sandbox Code Playgroud)
我怎么摆脱
``
Run Code Online (Sandbox Code Playgroud)
因为它自动添加
Kem*_*lah 22
添加第三个参数where()并将其设置为FALSE
$this->db->from('posted');
$st="infor='rent' AND (typeq='in' OR typeq='out')";
$this->db->where($st, NULL, FALSE);
$q = $this->db->get();
Run Code Online (Sandbox Code Playgroud)
$this->db->where()接受可选的第三个参数.如果将其设置为FALSE,CodeIgniter将不会尝试使用反引号来保护您的字段或表名称.