Welcome Guest, Not a member yet? Register   Sign In
Cutom string in where statement
#1

[eluser]zovar[/eluser]
CI user guide says that we can use custom strings in $this->db->where():

Code:
$where = "name='Joe' AND status='boss' OR status='active'";

$this->db->where($where);

My string is as follows
Code:
$where = " tag='test' OR tag='test1' ";

$this->db->select('id')->from('tags')->where($where);

i get the following error
Code:
A Database Error Occurred
Error Number: 1054

Unknown column 'tag='test'' in 'where clause'

UPDATE `notes` SET `title` = 'title' WHERE `tag='test'` OR tag='test1' AND `id` = '13'

as you can seen the first where statement gets escaped...
#2

[eluser]zovar[/eluser]
OK, i think I have figured this out. There is a third parameter in where() which disables the backticks.
where($string, NULL, FALSE)
#3

[eluser]Unknown[/eluser]
Thanks! That information helped alot Smile




Theme © iAndrew 2016 - Forum software by © MyBB