Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

codeigniter $this->db->where(); custom string problem

Im trying to select some values using a custom string. below is my code

  $this->db->from('posted');
  $st="infor='rent' AND (typeq='in' OR typeq='out')";
  $this->db->where($st);  
  $q = $this->db->get();  

A Database Error Occurred

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

i think the problem is coz of

WHERE `infor='rent'` 

when i manualy execute this code it works perfectly.

WHERE infor='rent' 

how do i get rid of

`` 

because its automatically added

like image 261
LiveEn Avatar asked Sep 25 '11 18:09

LiveEn


1 Answers

Add a third parameter to the where() and set it to FALSE

  $this->db->from('posted');
  $st="infor='rent' AND (typeq='in' OR typeq='out')";
  $this->db->where($st, NULL, FALSE);  
  $q = $this->db->get();

$this->db->where() accepts an optional third parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names with backticks.

CodeIgniter Documentation

like image 100
Kemal Fadillah Avatar answered Oct 17 '22 09:10

Kemal Fadillah