Welcome Guest, Not a member yet? Register   Sign In
Custom sql in active record
#1

[eluser]nonamez[/eluser]
I faced some problem with active record as it automatically adds accents. For example i need to use this
Code:
ORDER BY FIELD(sites.ID, 120, 27, 119)
, so i do it like
Code:
$this->db->order_by('FIELD(sites.ID, '.implode(', ', $sites).' )');
, but getting
Code:
ORDER BY FIELD(`sites`.`ID`, `120`, `27`, `119`)
I also tried to add apostrophes, but nothing has changed. Is there any way to do my query or i need to rewrite it as a simple query? And if so how to escape all values without loop (array_map) ?
#2

[eluser]TheFuzzy0ne[/eluser]
You can do that from within the SELECT portion of your query, and then order by that. You can see more information [url="http://ellislab.com/forums/viewthread/234265/#1050343"]here[/url] There's a lot of extra code, but look at the last part of the SELECT portion of the query. It should get you on the right track.
#3

[eluser]nonamez[/eluser]
[quote author="TheFuzzy0ne" date="1364385619"]You can do that from within the SELECT portion of your query, and then order by that. You can see more information [url="http://ellislab.com/forums/viewthread/234265/#1050343"]here[/url] There's a lot of extra code, but look at the last part of the SELECT portion of the query. It should get you on the right track.[/quote]

But is it possible to escape it automatically?
#4

[eluser]TheFuzzy0ne[/eluser]
Not for that particular part of the query, no. The Active record library was only intended to be simple, and for relatively simple queries. SQL syntax is quite complex, and in order for the Active Record class to understand it, it would need some kind of parser, which would add considerable overhead. At the moment, it understands the really basic stuff, but escaping more complex queries can cause problems.




Theme © iAndrew 2016 - Forum software by © MyBB