Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficient way to store html element in sql

I'm saving contents of a particular div in mysql database as html elements. So the html elements content includes many elements such as:

<div id="div0" class="box" style="z-index: 2; width: 1689px; height: 1013px;">
   <img style="margin: 0px; position: relative; display: block; height: 550px; width: 638px; top: 0px; left: 0px;">
</div>

Is there any way to reduce the data for efficiently storing in mysql database.

Such as any php or javascript functions to compress before saving to db.

like image 801
joHN Avatar asked Jul 12 '26 06:07

joHN


2 Answers

Why compress? Disk space is cheap, and storing it in a compressed (e.g. gzip) format will just cost you CPU time to decompress/recompress each time.

As well, once you compress the data, it becomes an opaque binary blob to the DB, and you lose any ability to search that text via substring/fulltext.

like image 160
Marc B Avatar answered Jul 13 '26 18:07

Marc B


You could compress the string before saving it to the database using gzcompress()/gzuncompress() PHP functions or you can do it with mysql using COMPRESS()/UNCOMPRESS() in your queries - but unless you have very much data I would not recommend this.

You win some harddisk space, but you lose a lot of transparency (search, edit, convert, migrate...)

like image 44
DerVO Avatar answered Jul 13 '26 20:07

DerVO



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!