Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
DB class, "and_on" statement with select
  • Hi there

    I'm building some query with the DB class, and i noticed something with the AND_ON statement. This is the doc content for this entry : 

    $c1 mixedrequired table name or array($table, $alias)
    $op stringrequired logical operator
    $c2 mixedrequired table name or array($table, $alias)

    With a ON statement no need the have other possibility  than tables name. But with a "and_on", i may want to do something else, like : 

    "SELECT table1.field1, table2.field1 FROM table1 LEFT JOIN table2 ON table1.field1 = table2.field1 AND table2.field2 = "JOHN DOE"

    The SQL ON clause isn't limited to table name, i can take values to. But FuelPHP wrap everything with grave accent, so values like my "JOHN DOE" are interpreted as tables and fire an error.

    Reflecting the query (if no john doe in field2, it return a data with field2 set to null, with LEFT in JOIN clause, i dont want the query's behavior to ommit results when field2 is null) I can't use WHERE clause, i have to put it in the ON.

    Temporary solution would be to just write my query inside on building it. Except if i'm wrong and there is a simple way to do it with query builder, can we imagine extending it with a method like "on_value" and its variation "and" and "or" , witch would wrap the third parameter with quotation marks instead of grave accent in a futur version ?


  • HarroHarro
    Accepted Answer
    If you need to include a literal, encapsulate it in a DB::expr() to prevent it being escaped/quoted.
  • As i thought there is always a solution. Thanks.

Howdy, Stranger!

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

In this Discussion