Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Storing serialised objects in the DB
  • Hey there,

    I'm on my long way of rewriting old Kohana cored software to Fuel.
    Just came across some issue, and I'm not quite sure how to solve it.

    I'm using QB to store serialised arrays in DB, however I can't unserialise them back for some reason.

    Old software used simple db->escape() and worked perfectly.

    In fuel QB i'm able to save it ( no matter I'm leaving escaping to QB or using DB::escape and DB::quote ), however unserialising it is a bit of problem.

    The only solution I have is to use base64 encode before saving and decode back while using, however I'm trying to avoid overhead on this as this part of the system is critical performance-wise.

    So the question is - how to propely escape this type data in Fuel  ?
    Any ideas ?
  • Fuel's DB layer is originally kohana's, so i'm not sure what we do different.

    I checked the code of the drivers we have, but the MySQL drivers uses mysql_real_escape_string(), the MySQLi driver uses the real_escape_string() method, and the PDO driver uses the quote() method.

    Which in all cases is the correct way of escaping them.

    Did you verify and compare the results, in other words does it go wrong on save (not does it save, but does it save exactly the same as in the kohana app) or on read? And if on read, how exactly do you read, fetch the value, and convert it into an object again?

    DB::quote() will not work, it requires a string as input, and will call __toString() in case an object is passed.

Howdy, Stranger!

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

In this Discussion