Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Read only query
  • Hi guys Me again, don't shout Harro but I'm asking another question :p I have the following query which runs fine using phpMyAdmin.
    SELECT IF( user_id =1
    OR user_id =2, friend_id, user_id ) friend
    FROM friends
    WHERE (
    user_id =1
    OR user_id =2
    )
    OR (
    friend_id =1
    OR friend_id =2
    )
    

    How can I convert this into ORM, or DB class? I tried doing a simple query()->execute(); but it gave me some error about being read only. SQL is where I'm my weakest so maybe someone can explain to me why, or help me getting it coverted to ORM, as I'd like to relate some models too, such as the user model.
    Regards,
    Jamie
  • You can't with ORM. With DB, you'll have to wrap the IF in a DB::expr(), to avoid escaping issues. As for the result, if you do a normal execute(), the DB result class returns direct driver results, for example in case of the MySQLi driver those are mysqli_result objects. These objects are immutable. Use as_object() or as_array() if you want the return data in a format that is mutable.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion