CMS: store custom pages as files or in MySQL database?

点点圈 提交于 2019-12-20 23:31:41

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/3384465/cms-store-custom-pages-as-files-or-in-mysql-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!