Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
DB Class
  • Hey, I seems to be getting some strange errors with the DB class, running this:
    $data['entry'] = DB::select()->from('mini_lists')->execute()->get();
    

    gets me this error: http://xdat.us/QBqvK.jpg is this a bug or is my syntax wrong? (its from docs) Update: Tried a normal query
     $data['entry'] = DB::query('SELECT * FROM mini_lists');
    

    it just outputs the query string get() and execute() only says
    Fuel\Core\Fuel_Exception [ Error ]: Database results are read-only
    
  • I' new to Fuel and I think my code is OK, but I have the same problem and I don't know how to solve it.
    It's a module ("Books") but the code is the same (with "\" before certain names, something I don't understand yet)
    namespace Books;
    
    class Controller_Books extends \Controller {
    
     public function action_index()
     {
      $data = array();
      $data['result'] = Model_Books::books_all();
      $this->response->body = \View::factory('welcome/index', $data);
     }
    
    The model works by itself and if I run the query directly on the controller, it does too. But I doesn't pass the "->execute()" result to the "$data" array. Here's the model:
    namespace Books;
    
    class Model_Books extends \Model {
    
     public static function books_all()
     {
      $result = \DB::select()->from('books')->execute();
      return $result;
     }
    
  • It's probably because a Database_Result object can't get past the output encoding. Also: next time create your own topic, you're hijacking an old topic to post a pretty unrelated question.
  • The get method gets you a specific column from whatever row you're currently on. The error you're getting is because you're not providing the name of the column - which the method requires.
  • There is no get() in executing a query:
    $this->record = \DB::select()->where('id', '=', $value)->from($table)->execute();
    
  • Harro Verton wrote on Thursday 7th of April 2011:
    There is no get() in executing a query:
    $this->record = \DB::select()->where('id', '=', $value)->from($table)->execute();
    
    Fuel\Core\Fuel_Exception [ Error ]: Database results are read-only
    

    gives me this error: Fuel\Core\Fuel_Exception [ Error ]: Database results are read-only
    COREPATH/classes/database/result.php @ line 248
    Update: using as_array() seems to return the results right but as_object() does not work.
    $data['entry'] = DB::select()->where('list_id', '=', '1')->from('mini_lists')->execute()->as_array();
    

    ErrorException [ Error ]: Call to undefined method Fuel\Core\Database_MySQL_Result::as_object()
  • That's not an error on the query itself. You're trying to directly modify the result of the query, which is impossible since they're accessed via an iterator (which is read-only). Next time please include the code that causes the error, so we don't have to guess...

Howdy, Stranger!

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

In this Discussion