Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Database class
  • I'm trying to work with the database class.
    I know the class is from the Kohana Framework. So I tried the following, but it doesn't work.
    What am I doing wrong?
    $users = new DB();
    
    $users->select('username', 'email');
    $users->from('users');
    $users->execute();
    $users->as_array();
    
  • I cant wait for more docs on AR Conventions;that will make an awesome read.Good work people.
  • Try this:
    $users = DB::select('*')
                 ->from('users')
                 //->where('user_id', '=', 1)
                 //->join('groups', 'LEFT')
                 //->on('group_id', '=', 'group.id)
                 //->or_where('user_id', '=', 'me')
                 //->limit(Pagination::$per_page)
                 //->offset(Pagination::$offset)
                 //->order_by('user_id', 'ASC')                            
                 ->execute()
                 ->as_object(); // as_array() is the default setting
    
  • Thanks. But I already knew that. I just wanted to know if there is a way to do something like that.
  • That was from some of my test Fuel code which works. That's all of the options Or are you asking something else and I am missing it? Do you mean the ActiveRecord package?
  • Ok, let's say I have an array like this: $input = 'this is a test';
    $keywords = explode(" ", $input); Now I want to use the DB class and foreach keywords use or_where.
    How can I do that? $result = DB::select('title')->from('articles')
    ->or_where()
    ->as_object()->execute();
  • Ah sorry forgot that one :-) I will amend the post thanks. The syntax for or_where is or_where($column, $op, $value) One way of achieving what you want is to put the db call in a for loop.
    $num = sizeof($keywords);
    for($i=0; $i < $num; $i++)
    { 
      $result = DB::select('title')
                    ->from('articles')
                    ->or_where('your_field_name', '=', $keyword[$i])
                    ->as_object()
                    ->execute();
      // Do some processing with the result
    }
    
  • David, have a look in the code of activerecord/classes/model.php You'll find lots of examples for DB:: there. ActiveRecord builds uppon DB::

Howdy, Stranger!

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

In this Discussion