哪里最好将html页面存储在数据库或文件本身中?
如果我有很多文件:
用户/ login.php中
用户/ register.php
用户/ somethingElse.php
物品/ index.php的
物品/ view.php
物品/ somethingElse.php
并将所有代码存储在那里,或者将这些页面作为html存储在数据库中,然后将其呈现为只有一个文件content.php?
答案 0 :(得分:1)
我可以说将HTML存储到文件中要比DB好得多,因为
1)For retrieving data also you need to perform DB operations as well,so it may stuck DB somewhere when load is become a 'real load' to operate DB
2)A DB can crash but a file cont much when compared to DB
3)If you want to change the HTML you need to perform agian update operation for that which makes big issue for an developer to work
4)And also in DB you need to store HTML tags,other things using 'htmlentities' which causes conflict
答案 1 :(得分:0)
您可以将HTML代码存储在PHP文件中,也可以使用HTML文件并让PHP获取这些文件。
答案 2 :(得分:0)
我喜欢这样做的方法是在我的root中保留尽可能多的HTML:/index.php-file然后根据用户想要看到的页面加载我需要的文件。
F.X。用户想看看我发送给index.php?page = articles的文章,加载页面布局和include(“articles / index.php”);这也可以让你使用htaccess使网址看起来更好。
但是作为一般规则,不要在你的SQL中保留HTML代码,除非它是用户提交的内容。