Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it acceptable to store HTML in a database?

Status
Not open for further replies.

AndyInNC

Programmer
Sep 22, 2008
76
US
I have always tried to keep a separation in my coding (N-tiered development it used to be called; now in .Net it is MVC) but it has recently come up that it can be "better" to store some code inside database tables. This seems REALLY hard to troubleshoot and / or maintain.

Does anybody reputable say this is a good idea?

Thanks.
 
Not sure if you consider me reputable, but personally, I would not store important HTML in a database.

As you say, maintaining will a pain as you would need either an interface to your DB to edit the HTML, or direct access to it, and edit in a small text editor directly there.

Other than that, obfuscating where the HTML is coming from can cause issues when another developer comes along to maintain it, and would need to search tables to find HTML.

Also, I can see no database schema where having an HTML table would make sense.

The only thing I can see that would store some HTML in a DB is a blog or forum. Where it would be storing the post's HTML. But that should be very basic, and would likely not need to be edited directly but through a web based editor.

But I think storing HTML that is an actual part of the website design and layout is just making things much more cumbersome than they need to be.

Also how is this related to PHP? PHP would just echo out the HTML. I think maybe posting in the forum for the DB you are using may have been more adequate.

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Does anybody reputable say this is a good idea?

It's not a good idea for the reasons you mentioned.

Personally I've always preferred using a kind of pseudo markup language, much like BBCode does and just expand it at 'run time'.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Thanks for the thoughts.

What is the relevance to PHP? Well, I guess it's only a small tie-in.

<story type='long, boring'>

I have a PHP subroutine that you can pass some data and a css class and it will build an HTML table from that. I've had it for years and it works pretty well. Usually it's not the final output, but it's a development placeholder. (Although, in a couple of instances it's worked just fine for the finished product!)

My boss has taken up programming as a hobby, found this code and loved it! He decided to move a lot of his presentation code into stored procedures & tables and pass that into my HTML table generator.

We recently got a new domain name and split the site in two and I had to search through the tables, views, & stored procedures to make changes.

</story>

When I searched for "HTML stored in database", I was surprised how many people liked the idea. I thought it could be related to development for mobile apps.

Thanks for the thoughts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top