Heavy content site all stored in database?

Hey guys,

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 very much!

Not really, databases are more for storing small chunks of data, instead of large blobs of content. It can still be done, but not as well.

Yes and no, and not necessarily in that order either.

Yes it will.

Not many fields as such, but lost of rows definately.

Yes it would.

The database always imposes a performance penalty over not using one at all.

I think that you’re doing pretty well.

Thanks for the answers. :slight_smile: 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)?

Typically if you’re using a content management system, there will be a tried and tested caching solution that goes along with that system.

That depends on your intended usage.

Is the content going to change frequently, or infrequently.

They’re dealing with automated changing of content, which is quite a specialised side of things, that is used by sites like Wordpress and Facebook.

So, what is your intended usage. There are hundred of solutions out there, all catering to different special needs.

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.

Thanks a lot pmw. You’ve been extremely helpful.

I still have loads of questions so I’m gonna keep asking them, so don’t feel obligated to answer them all. :slight_smile:

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.)

There’s a couple of ways to go on this. Where the common content is self-contained, such as with headers and footers, an include can work quite well.