Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Auto-quote by where statement in DB Class
  • Hey guys,
    I wrote a query ( using "Closure Tables" pattern ) manually and I've tried to re-write this using DB class ... but ... I realized that the value, in where statements, is auto-quoted, then ...
    DB::select()->from('pages')
     ->join('pages_rel')->on('pages.id', '=', 'pages_rel.desc')
     ->where('pages_rel.asc', $child)
     ->and_where('pages_rel.desc', '!=', 'pages_rel.asc')
     ->execute();
    

    producing :
    SELECT * FROM pages JOIN pages_rel ON (pages.id = pages_rel.desc) WHERE pages_rel.asc = 3 AND pages_rel.desc != 'pages_rel.asc' This query cannot work because the value is quoted ... the right query must be :
    SELECT * FROM pages JOIN pages_rel ON (pages.id = pages_rel.desc) WHERE pages_rel.asc = 3 AND pages_rel.desc != pages_rel.asc Does exists a solution or I have to use DB::query()??
  • Use DB::expr()
  • Yes, but if I use DB::query() it already works. I wanted to know if this query could be created using DB class functions like "select()", "where()", ... or if I must have to use DB::query() Thank you
  • He means using DB::expr
    DB::select()
          ->from('pages') 
          ->join('pages_rel')->on('pages.id', '=', 'pages_rel.desc') 
          ->where('pages_rel.asc', $child) 
          ->and_where('pages_rel.desc', '!=', DB::expr('pages_rel.asc'))
          ->execute();
    
  • Whoooops
    I misunderstand it, sorry guys and thanks for your support

Howdy, Stranger!

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

In this Discussion