Storing HTML/Javascript in MySQL?

Hi All,

I'm working on upgrading a website that I maintain, which is built in PHP with a MySQL database.

I have some ads on the site, and they each have some HTML and Javascript, which is used for imbedded photo galleries and live Google maps.

Right now I have each ad in a separate PHP file, and use Include to pull the ads into their proper pages.

It's getting to be too much to store them in PHP files, and too confusing to have to edit each file when the ads change, so I want to put them into the MySQL database.

I want to be able to store the HTML and Javascript for each ad in a text column, and later SELECT the proper ad for each page and insert it.

I'm confused as to how to store the HTML/Javascript in MySQL.

Do I just use htmlentities() to encode the HTML/Javascript before inserting into MySQL, then use html_entity_decode() to decode it when I pull it back?

Will htmlentities() properly handle the Javascript?

Is there any problem with this?

Please note that I do want to store the code for the ads in MySQL, not only to make it easier, but also so I can later set up a page where the advertisers can go in and change their own ads. Also, as the site becomes more popular, I will be spreading the load out over multiple servers, so I'll need a central database to store the ads for all of the webservers.

So, continuing to use the include files, or using a flat-file won't work. This has to move to MySQL!

Thanks for your help and suggestions!


(She's baaaackkkkkkk!!!!)



  • I also want to do the same thing.
    Please tell me which data type is used to store javascript code in mysql.
    And after that how to fetch that javascript from mysql?
    Please guide

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion