PDA

View Full Version : Embedding php in html VS generating full pages?



zicemaster
May 8th, 2006, 12:50 AM
Title! ^_^ Which is more efficent or prefferable?

Do most websites generate the html for the header and footer? Or is only the content pulled out of the database?

I know how to do it either way... Just wan't to know whats better!

noTime
May 8th, 2006, 02:23 AM
Embedding PHP is much easier - you don't have to mess with hundreds of echos. But if your page is very dynamic, you should consider writing the whole page in PHP. Then you can manipulate with any part of the document.

Well, there are three ways of inserting a template into PHP (my beloved :love:):
- You can split the (x)html page into static blocks and write PHP code between them. Unfortunately, you may lose the flexibility of this (x)html code. Anyway, it's a good and efficient way to make a site with several templates.
- The second way is similar to the first one, but the data is stored in your DB. Congrats if your hosting provider doesn't limit the amount of SQL requests, but using SQL may slow down the server. That's why this way is slower.
- OK, now you can drop all of your (x)html into PHP's echos. The point is - it slows down the server (the time of load too). Moreover, your code may become messy: it will be difficult to make your page look different, right? :)

Last tip: SQL databases should be used to hold your data, not your templates.

zicemaster
May 9th, 2006, 03:28 PM
Yea... I was kinda worried about my Mysql passwords when embedding PHP... Thats why I was wondering! :)

Btw... I use bluehost, not sure the request limit but it is probably okay. 50MySQL databases and 50 PostGreSQL.

Is there any big diff between the database types?

noTime
May 10th, 2006, 12:52 AM
Yes, the speed of those two differ - MySQL is the fastest in the world. :)

It doesn't matter how db's you have got. For example, my hosting company made a 10000 sessions per week limit to prevent server's overcharge.