Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Database results are read-only
  • When I assign edresults to view by DB::query.

    I got Database results are read-only.


  • HarroHarro
    Accepted Answer
    By default DB queries return their results in the drivers native format, for performance reasons.

    For example, in case of MySQL, MySQL_Result objects are returned. These objects are provided by the PHP driver, and are readonly.

    In FuelPHP, for security reasons, everything you pass to a View will be encoded. This means you can't pass DB results directly to a View, since encoding means modifying, which you can't do with a read-only object as you have noticed.

    Several solutions exist:
    - use ORM, it's objects don't have this issue
    - use as_array() to convert the result to an array
    - use as_object('stdClass') to convert the result into standard class objects (which are read-write)
    - Whitelist the result objects in your config.php (not recommended for security reasons)

Howdy, Stranger!

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

In this Discussion