2

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.

9
  • 1
    Is there a reason why you're looking to compress it? Are you having storage or performance issues? Commented Feb 1, 2012 at 17:37
  • @Fosco: maybe he's storing really large fragments and they don't fit :-) Commented Feb 1, 2012 at 17:38
  • You could always base64_encode() the string to compress it slightly. It may not make much of a difference though in length. Commented Feb 1, 2012 at 17:40
  • @Tim I don't think base64_encode will help much on this ;) Commented Feb 1, 2012 at 17:46
  • 1
    @Fosco: The field is too large and I think its not best practice to store too large data in single field. I'm storing a html prototype inside a div (the application is a wire frame builder ) Commented Feb 1, 2012 at 17:52

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

4

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...)

1 Comment

I used gzcompress along with the BLOB datatype for db fields, Details

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.