Welcome Guest, Not a member yet? Register   Sign In
Active record WHERE problem...
#1

[eluser]Thomas @ BBP[/eluser]
Hi guys !

For my project I need to execute that kind of queries :
Code:
SELECT * FROM (`my_table`) WHERE 1 IN (e_type)

But when I use active records, it seems I can't do that kind of stuff, because that CI active record :
Code:
$this->db->where("$params[type] IN (e_type)");
$query = $this->db->get('my_table');

...makes that query :
Code:
SELECT * FROM (`lm21_events`) WHERE `1` IN (e_type)

And in my case, the ` changes the meaning of my query...

Does anyone got an idea ?

Thanks for your help !
#2

[eluser]Sudz[/eluser]
Try this one
Code:
$this->db->where_in($param['type'],'e_type');
$query = $this->db->get('my_table');
#3

[eluser]Thomas @ BBP[/eluser]
Hi Sudhakar@CI !

Thanks for your answer.

But unfortunatly, I've test it, and the result is quite the same :
Code:
SELECT * FROM (`my_table`) WHERE `1` IN ('e_type')

If I can't find any solution, I'll made another try without active record...

#4

[eluser]davidbehler[/eluser]
Why not do it the other way round?
Code:
$this->db->where_in(e_type, $param['type']);
// or stop where() from escaping your query by passing FALSE as the third parameter
$this->db->where("$params[type] IN (e_type)", NULL, FALSE);
#5

[eluser]Thomas @ BBP[/eluser]
Great ! Seems to works !

After testing this solution, I've take a look into the Code Igniter Active Records doc and I've seen that two lines saying :

Quote:$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.

$this->db->where('MATCH (field) AGAINST ("value")', NULL, FALSE);

I've missed those two lines, too bad for me !

Thanks a lot for your help !




Theme © iAndrew 2016 - Forum software by © MyBB