chiba Posted July 16, 2012 Share Posted July 16, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/265778-different-ways-of-building-a-site-html-php-mysqlphp/ Share on other sites More sharing options...
cpd Posted July 16, 2012 Share Posted July 16, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/265778-different-ways-of-building-a-site-html-php-mysqlphp/#findComment-1361959 Share on other sites More sharing options...
KevinM1 Posted July 16, 2012 Share Posted July 16, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/265778-different-ways-of-building-a-site-html-php-mysqlphp/#findComment-1361961 Share on other sites More sharing options...
chiba Posted July 16, 2012 Author Share Posted July 16, 2012 So it's better to have a php page for each of my pages; index.php, about.php, photos.php,... and have header.php, footer.php, menu.php for common parts of all pages? Quote Link to comment https://forums.phpfreaks.com/topic/265778-different-ways-of-building-a-site-html-php-mysqlphp/#findComment-1361963 Share on other sites More sharing options...
ignace Posted July 16, 2012 Share Posted July 16, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/265778-different-ways-of-building-a-site-html-php-mysqlphp/#findComment-1361966 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.