Jump to content

Benefits of using DB to store site layout/content?


unsider

Recommended Posts

I never really gave it much thought, but are there any positive benefits to this method?

 

I'm talking simply writing your layout code, or any code, into your DB as longtext, and then calling/outputting with a simply query.

 

 

 

Link to comment
Share on other sites

  • 3 weeks later...

Well the MySQL and PHP combination to store site content works very well for me. I'm still a novie in web design and hence stilll assessing more of the benefits of the two technologies.

 

My first professional site which I'm almost finished with is for a local school, the site would be administered by people who don't have knowledge on how to do basic html but they would still need to make regular updates without having to use any code or WYSIWYG.

 

So with the help of a friend, I have designed an administration page where they can simply make changes to the content by typing into "text areas" and save, the data saved into the text area is saved into a db and it is this data which will be displayed on the main pages that the visitors can access...

 

Great benefits (...so far!)

Link to comment
Share on other sites

Your database could end up massive! I would never use this approach. Use a template system.

 

Not really I store a whole site in a database and it takes under a 1 mb 

 

MySQL is a great solution for storing a site because you can do so much more so easily with the data over a flat file

       

For example all my pages are made by a 6 step process

1) Url is rewritten to my index processor like index.php?page_request=example.php

2) The get var $_GET['page_request'] is queryered against the database if found it gets the pages content error else a 404 page message

3) The shell is collected out of mysql (top and bottom piece)

4) Shell top is loaded via Eval

5) Content loaded via eval

6) Shell bottom loaded via eval

 

Now advantages to my system is I can take my content area and pull keywords out of it based on tag structure (h1,h2, first words of paragraphs etc.) and then use those as my meta tag keywords for the page.

I can use the last updated time for that content area right out of mysql to satisfy that header

I can use my keywords to do fulltext searching quickly and effectively.

I have no requirements to manage any flat files so I can login and manage a site from any where I can get online

 

The only downside is the framework I wrote was 2 years of refining and still can be refined farther. But I have a passion for my CMS's framework so.

Link to comment
Share on other sites

If you're just using a database to store entries and not using the SQL capabilities of sorting, joining, comparing, etc., why not just store your data in an xml file?

 

For example:

<?xml>
<page>
  <title>my title</title>
  <section1>text that goes in section 1 div</section1>
  <section2><![CDATA[
    <b>html code</b> that <i>goes</i> in section 2 div
  ]]></section2>
</page>

 

Then use simplexml in your php script to pull out the nodes of the xml file and include them where ever you want, like in a template.  There's no mess.  The data is easily readable by a human and editable with just a text editor.  There's no need to log into a mySQL server everytime a page loads.  I'd be willing to guess that it's also faster and less CPU intensive for small amounts of data.  Also, since xml files are stored as files on your server, you can easily make a backup of your website and data by just copying all the files; no need to worry about saving db dumps.

Link to comment
Share on other sites

I'm not sure what you mean, cooldude.  I'm suggesting to use a php template that calls xml structured data instead of mysql database rows.  The speed aspect isn't the main reason I think xml is better.  Like I said, if you wanted to sort, search, join, compare data, I would definitely use mysql.  But for the purposes of just reading in structured data directly, xml seems like a simpler choice, and this seems like what the OP wanted.

Link to comment
Share on other sites

xml u stil need a raw file unless you go database -> xml -> xhtml which just adds a step

 

I don't know where all these myth's came about about mysql being so slow would some one like to answer that?

 

The only thing about your approach that I completely disagree with is the use of eval() so much.  It's SO slow compared to normal PHP code execution.

Link to comment
Share on other sites

no a lot of the content area actually execute classes that are built around that page's content area to promote a consistent view.

 

I haven't noticed bad times on any pages yet for load using eval.

 

I also need it because my site does auto wiki links turning words into internal links.

 

However I might change that later and do smarties because they are going to be really tricky.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.