So it is a good idea to store paragraphs of text and other content in a database field for a website that is pretty content heavy, right? For example, there are many pages explaining topics in depth, maybe 5-10 paragraphs of text on each page. Is it ideal to store the HTML code in database fields rather than storing that text in the actual PHP files?
The thing I am confused about when doing it this way is, doesn’t that mean the server will have to query for this content every single time the page is accessed by users? Furthermore, doesn’t this mean there would be many, many fields in a table just for html code? Wouldn’t it be easier to just send the php file with text included, rather than querying for it? I’m not sure which would yield a better performance. Can you guys open my eyes up here?
Thanks for the answers. So someone once told me it was a better idea to use a database for this content, but only if you have a good caching system. How exactly would I implement such a system?
Any opinion on what the better idea would be here? Content stored in database, or in PHP files? Do you think Wikipedia stores their large amounts of text on different articles in a database? Text file? server side script file (e.g. PHP / ASP)?
Well… intended usage for this would be static articles explaining things that shouldn’t change much at all, but should still be open to change. You know what I mean? Definitely not like Wikipedia where users can modify the content.
I guess you can think of it as a textbook sort of. It stays the same for a while, but may be modified and reproduced with minor changes in a new edition.
And who will be making the changes. You and a group of other editors?
If it’s just yourself and perhaps a few others, you can get away with static content. You can even use sites like CushyCMS that provide a nice interface for editing your static HTML content via an ftp connection.
I still have loads of questions so I’m gonna keep asking them, so don’t feel obligated to answer them all.
Anyway, so if I do go the static content in PHP file route, as opposed to content in database records, would I just use a PHP include on each of those files to get the layout and static info, like the header of the page and core navigation / footer (and perhaps that HTML would be in a database? or maybe just in a PHP file using echo?)?
Because it seems a bit redundant to paste the same HTML code in all the PHP files. Also, it opens up to more errors. A PHP include would just have the server grab that HTML content and spit it out instead of the user’s client browser, right? So you thinking an include would be better than the same HTML on each PHP file?
Yes, you would definitely want to use an include. Either on the pages themselves, or have a main index.php file that includes the layout and page file that should be loaded. (You would definitely want to make sure paths can’t be injected into your script… so be careful.)