Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
General
Query Binding Problem Convert String automatically
viyancs
April 2013
I have problem When I want to Passing field as parameter using QUERY BINDING, here my code
SELECT * FROM USERS ORDER BY :field :sort ;
When I am Check with echo DB::last_query(); the query show like this
SELECT * FROM USERS ORDER BY 'updated_at' 'ASC';
that query cannot sort because detection as string on mysql, How I can fix this ? any suggestion ?
Harro
April 2013
Accepted Answer
Encapsulate the variables you pass in DB::expr(), which will prevent them being treated as strings.
viyancs
April 2013
thanks that is work
:)
Harro
April 2013
1.6 now has DB::identifier() to solve this issue, DB::expr() disables all quoting, which is not a good solution.
DB::identifier('user.id') will return `user`.`id` (if you're using MySQL), so properly quoted.
viyancs
May 2013
why
DB::expr() is not good solution than
DB::identifier('user.id') ?
actually I am still using old version
:(
Harro
May 2013
Because you should quote all identifiers for security reasons (and for possible column name vs keyword conflicts).
It's not a problem to use DB::expr(), but you will have to quote your identifiers manually (which makes your code not portable anymore).
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,088
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
260
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
May 2013
viyancs
May 2013