Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
like clause on multiple fields
  • Hi all,
    I wanted to know if it was possible to have a Model execute the following query: select * from table_name where concat_ws(' ',first_name,last_name) like '%c%'
    Thanks!
    Met
  • What's wrong with this code, plz? $data = DB::query('SELECT * FROM table_name')->as_object()->execute();
    $this->response(View::forge('search/results', $data)); It gives me a the following error: Fuel\Core\FuelException [ Error ]: Database results are read-only
    COREPATH/classes/database/result.php @ line 266 ...while $data = DB::query('SELECT * FROM table_name')->execute()->as_object();
    $this->response(View::forge('search/results', $data)); gives me this: ErrorException [ Error ]: Call to undefined method Fuel\Core\Database_Result_Cached::as_object() Thanks,
    Mat
  • met b wrote on Saturday 7th of January 2012:
    I wanted to know if it was possible to have a Model execute the following query: select * from table_name where concat_ws(' ',first_name,last_name) like '%c%'
    Not with any of the default methods, you'd have to use DB::expr() to do this, something along these lines (haven't tested it, but I think it'll work):
    $examples = Model_Example::query()->where(DB::expr('CONCAT_WS(" ", `first_name`, `last_name`)'), 'LIKE', '%c%')->get();
    
  • You haven't been using things like forums very long have you? It's considered polite to post stuff where it belongs, thus never hijack another topic (not even your own) with a totally unrelated question. That's called "going off-topic". If you have a second question that's unrelated, create another topic. And create it in the right place, this forum is about the Orm and your question is about the Query Builder and thus should have gone into the general forum.
    I shouldn't answer this, but just delete the post and have you ask it in the right place. Though for this once I will answer here.
    met b wrote on Saturday 7th of January 2012:
    What's wrong with this code, plz? $data = DB::query('SELECT * FROM table_name')->as_object()->execute();
    $this->response(View::forge('search/results', $data)); It gives me a the following error: Fuel\Core\FuelException [ Error ]: Database results are read-only
    COREPATH/classes/database/result.php @ line 266 ...while $data = DB::query('SELECT * FROM table_name')->execute()->as_object();
    $this->response(View::forge('search/results', $data)); gives me this: ErrorException [ Error ]: Call to undefined method Fuel\Core\Database_Result_Cached::as_object()
    The second error is quite clear: there's no as_object() method on the result of execute(), thus that is invalid code. You can't call ->as_object() on the Database_Result_Cached object returned by execute(). As to the first error: first read up on security in Views. Everything that you don't mark as safe is encoded when you send it to the view, this is the case for database results as well as for any other data. Now database results are unmutable while they're in a result object, thus the encoding causes this error.
    The solution is either to have it returned as an array (which can be encoded) or pass it as a safe value to the View: $view->set('result', $result, false)
  • Hi Jelmer,
    thanks for the response. As espected it worked! You're right! I haven't been using forums that much. So I apologize for being off-topic. Keep on the good work!
    Met

Howdy, Stranger!

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

In this Discussion