Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
DB docs for Fuel
  • I haven't wanted to get too involved with the Database query builder stuff as I know Dan is (meant to be at some point) rewriting most of that. If it were to stay, could we not just add is_array() to the first argument to accept an assoc array of where conditions? We could even continue supporting the 2nd paramater to say all of these things should !=.
  • Damn, i'd hoped this query builder was more like in CI or Kohana 2.x. I really enjoyed the part where you could do something like that: $params = array('column1' => 'foo', 'column2' => 'bar');
    $this->db->select('*')
    ->where($params)
    ->get('table');
  • What's wrong with:
    DB::select()->from('table')
        ->where('column1', '=', 'foo')
        ->where('column2', '=', 'bar')
        ->execute();
    
  • Nothing's wrong until you want to make query more flexible, like what if our query has several JOINS which give us access to several possible variations of WHERE clauses. In case of CI query builder i could use one model method to retrieve data for several controller methods. Controller method 1:
    $params = array('column1' => 'foo', 'column2' => 'bar');
    $data = $this->my_model->get_data($params);
    

    Controller method 2:
    $params = array('column3' => 'foo', 'column4' => 'bar');
    $data = $this->my_model->get_data($params);
    

    Both of these methods retrieve data from same model method, but they use different params to retrieve different data. Right now i'd have to either use two different model methods or use several method params + if/else checks to get desired data.
  • Even though I don't like everything about this DB class it is a lot more flexible than CI's in my experience. Your main point seems to be that ->where() doesn't take array, which may be a nice feature suggestion. Also you can already do pretty much the same like this:
    $params = array(array('column1', '=', 'foo'), array('column2', '=', 'bar'));
    $select = DB::select()->from('table');
    foreach ($params as $where)
    {
        $select->where($where[0], $where[1], $where[2]);
    }
    $select = $select->execute();
    
  • Well, indeed, for the most part current query builder is more flexible, but i do really miss ability to simply drop arrays in methods such as where, where_in (that one too is so much needed) and some others.
    Thanks for your suggestion.
  • Excerpt from the above manual:
    You can use any operator you want. Examples include IN, BETWEEN, >, =<, !=, etc. Use an array for operators that require more than one value.
    [...]
    $query = DB::select()->from('users')->where('username', 'IN', array('john','mark','matt'));
    
  • Thanks! Looks quite simple.
  • Jelmer Schreuder wrote on 02/09/11 8:40 am:
    Excerpt from the above manual:
    You can use any operator you want. Examples include IN, BETWEEN, >, =<, !=, etc. Use an array for operators that require more than one value.
    [...]
    $query = DB::select()->from('users')->where('username', 'IN', array('john','mark','matt'));
    

    I use this in my code to take properties of some pages with 1 query:)

Howdy, Stranger!

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

In this Discussion