Jump to content

Different ways of building a site HTML, PHP, MySQL+PHP,...


chiba

Recommended Posts

Hi all,

 

I have built a site where the pages are stored on a mysql database and there is one index.php file that all the page data is loaded into. Is this a good way of building a site. Each page in the database is only HTML content. I understand that I cannot put php or javascript into the database, is this correct?

 

:confused:

It doesn't sound great in all honesty. You shouldn't be putting entire pages into a database and just retrieving them its a very bad design and I'd imagine puts strain on the servers. You should be writing HTML in PHP pages, ideally, and putting snippets of PHP code in to do what you want.

 

A combination of HTML, CSS, PHP and a MySQL back-end (dependent on whether or not its needed) are ideal but your styling, and DOM etc shouldn't really be kept in the database in its entirety.

No, don't put entire HTML pages in a database.  Databases are for data.

 

The basic idea is this:

 

You store data in a database.

Requests for that data are handled by PHP, which queries the database for that data.

PHP then puts the data in the correct template so it can be viewed.

 

These templates are PHP files, but are largely HTML.  There's just enough PHP within them to echo the data at the appropriate spot in the markup.

Yes. The reason being is that if your website changes (re-design for example) should not include editing the content in your database. Storing everything in the DB has certain drawbacks you may not be aware of. For example imagine the client asks you to display his latest tweets on his website in real-time. You can't put it in your DB.. so this means you will have a copy of your website in the DB and now also on the file system for those pages that require the tweets. This is just off the bat, I am sure there are more drawbacks, but I imagine you now understand when storing your entire website in the DB is not a good idea.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.