Possible Duplicate:
What structure type do I use for HTML content (MySQL)
What's the best way to store HTML code in MySQL?
If I have, let's say an entire page of source code, and I want to save it, what data type should I use for the column in MySQL?
Also, is it better to just save the code as a file, with a filename equal to the primary key, a unique id, created in MySQL (maybe to save space in the data file?)
Storing HTML code is fine. But if it is not from trusted source, you need to check it and allow a secure subset of markup only. HTML Tidy library will help you with that. Also, you need to count with a future change in website design, so do not use too much markup, only basic tags.
you can save the html codes just like text. You can use varchar(max) type column to save the html code in table. Display the code is depending the browser. But if you use nvarchar type that will cause problems in display.
I would recommend TEXT. I think blobs are more for multimedia etc. than text.
wikipedia blob
Data type to store HTML in Database would be TEXT
But, you have to encode it using mysqli_real_escape_string
$dbh is the database connection handle you used to connect to your MySQL instance using mysqli_connect()
$html="Yor HTML"; $sql = "INSERT INTO tbl (html) VALUES ('" . mysqli_real_escape_string($dbh,$html) . "')"
or use Prepared Statements
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With