Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Exception question
  • Hi, sometimes I get an exception in my log file, something like this:

    [01-02-2015] - Database results are read-only


    Is there a way to also show which file and line number is causing this issue?
  • That is not going to be easy.

    This exception is thrown by Database_Result, and it trying to find the caller means searching through the backtrace. You get all backtrace information in everything but the production environment, so these issues should have been found during development and testing? In production it would show the user an error screen, so I'm sure they can tell you what they did when it happened? Or are we talking about an API?

    Assuming that you don't deliberately assign data to a database result object, the most obvious place for this to happen is when you pass a database result object to a view.
  • I really don't know yet what is causing this error... It is sometimes there on production...
  • I know what is causing it. You're trying to assign or update a value which is the result of a DB call.

    Something like this will trigger it:

    $result = DB::select()->from('table')->execute();
    foreach($result as &$row)
    {
        $row['id'] = intval($row['id']);  // DB results are immutable!
    }

    The only place the framework will attempt to do this for you, is when you pass a DB result to a View. Since by default the View will try to encode all data, it will update the values passed.

    Addressing this is on my todo list, hopefully in time for 1.7.3.
  • Yeah the encoding thing is the problem, but can't find the line that is causing it...
  • I'll see if I can find the time tomorrow or this weekend to fix this issue.

    Since 1.7 objects can have custom encoders, but this was never implemented for Database_Result.
  • Ok cool thanks!
  • Just pushed to 1.8/develop. Can you check if this solves your problem?
  • Ok cool, no extra settings/changes needed?
  • So now I can remove all the "->as_array()" when I pass data to the view?
  • Yes, both the plain result of ->execute() and ->as_object()->execute() should work fine now.

Howdy, Stranger!

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

In this Discussion