Douglas Douglas - 2 months ago 33
MySQL Question

Store html entities in database? Or convert when retrieved?

Quick question, is it a better idea to call

) before or after inserting data into the database?

Before: The new longer string will cause me to have to change the database to hold longer values in the field. (
could change to a 804 char string)

After: This will require a lot more server processing, and hundreds of calls to
could be made on every page load or AJAX load.

SOOO. Will converting when results are retrieved slow my code significantly? Should I change the DB?


I'd recommend storing the most raw form of the data in the database. That gives you the most flexibility when choosing how and where to output that data.

If you find that performance is a problem, you could cache the HTML-formatted version of this data somehow. Remember that premature optimization is a bad thing.