Hi I’m starting to query my database in codeigniter and everything is working fine on a basic select statement but after I added my sql functions everything turns down. Well basically I have a function to Propercase text in mysql which supposed to work like this:
SELECT proper(foo_bar) as foo from foo;
this one should return something like this:
|Foo |
|Foo Bar|
Now applying the active records I expected it to be like this:
$this->db->select('proper(foo_bar)');
$query = $this->db->get('foo');
Well I still don’t know the part of aliasing but I need to solve this one for now but yes there is no return after this query. I think the CI read it as
Select 'proper(foo_bar)' from foo
which is obviously totally wrong.
And by the way, as much as possible I don’t want to manually key in my query like this:
$query = $this->db->query("SELECT proper(foo_bar) as foo from foo");
that would be impractical in my opinion. Any way to solve this? Thanks!
As stated by doc you should pass a second parameter to avoid field protection with backticks.
https://www.codeigniter.com/userguide2/database/active_record.html#select