I am creating a custom CMS in PHP (written from scratch) and want to know whether I should store user created pages as files or in a MySQL database.
The content is all HTML code, at least for now.
I cannot decide which to do as writing files with php seems like a security risk, and retrieving file contents from MySQL on every page load feels wrong (and could be a performance issue?).
I also have custom pages coded by me for a blog, etc. These contain PHP code but do not need to be modified by the user. Currently I am planning to store these as php files as its easier to upload them and edit them like that, but they could also be stored in MySQL.
I would greatly appreciate any help on what the right thing to do is, or at least what you would do.
You'd be better off storing content in the database. Note that you store content, not the entire HTML page (otherwise, you're not really building a content management system).
If you implemented it using plain files then you'd have to invent a file format for storing your structured data in, you'd have to figure out how to make it fast, worry about data integrity and race conditions, and more. With a database you get all this already done for you and it's done well and fast.
It's quite normal to do a database query on every page view; indeed it is typical for web apps to do more than 5 and up to 30 database queries on every page view, and I would guess that stackoverflow.com would probably fit into that range.
MySQL is fast enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With