| | |
Best compression
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
Hi and I am looking for a compression mechonism that can compress text (just letters and numbers) into binary or all weird symbols. Does anybody know of any good php/mysql codes as I can't get any to work.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - MacGyver Fan
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - MacGyver Fan
I have tried running the following mysql queries through the phpmyadmin command console (mysql_query() code) but I seem to be unable to retrieve the value. Here is my code.
Also tried
Please advice on how I should use the select query.
INSERT INTO `table` SET `column`=COMPRESS("abcd") SELECT * FROM `table` WHERE UNCOMPRESS(`column`)="abcd"
INSERT INTO `table` SET `column`=COMPRESS("abcd") SELECT * FROM `table` WHERE `column`=COMPRESS("abcd")
Last edited by cwarn23; Sep 18th, 2009 at 2:24 am.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - MacGyver Fan
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - MacGyver Fan
I think I may have found something with the bzip2/bz2 library because the gz library didn't compress very well. I will try storing the bzcompress() result in a binary column. Well let you know how my result goes.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - MacGyver Fan
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - MacGyver Fan
•
•
•
•
I have tried running the following mysql queries through the phpmyadmin command console (mysql_query() code) but I seem to be unable to retrieve the value. Here is my code.
Also triedINSERT INTO `table` SET `column`=COMPRESS("abcd") SELECT * FROM `table` WHERE UNCOMPRESS(`column`)="abcd"
Please advice on how I should use the select query.INSERT INTO `table` SET `column`=COMPRESS("abcd") SELECT * FROM `table` WHERE `column`=COMPRESS("abcd")
PHP Syntax (Toggle Plain Text)
SELECT * FROM `table` WHERE `compressed` = compress('test')
The only thing I can assume is the column containing the compressed data has to be a blob or varbinary type.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
I just tried varbinary like before and again varbinary didn't work however I tried blob which I have never heard of before and it worked! Also the bz library works but won't decompress. So using the method you have described how can I decompress the result?
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - MacGyver Fan
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - MacGyver Fan
•
•
•
•
I just tried varbinary like before and again varbinary didn't work however I tried blob which I have never heard of before and it worked! Also the bz library works but won't decompress. So using the method you have described how can I decompress the result?
You can just decompress the result in the SQL query:
PHP Syntax (Toggle Plain Text)
SELECT uncompress(test) as test FROM `table` WHERE `compressed` = compress('test')
This should give you the column test in decompressed form.
Note:
I wouldn't use:
PHP Syntax (Toggle Plain Text)
SELECT * FROM `table` WHERE UNCOMPRESS(`column`)="abcd"
The reason is that you'll run uncompress() on each row in the database table.
You will also be unable to use any index made on that column.
If you use:
PHP Syntax (Toggle Plain Text)
`column`= COMPRESS("abcd")
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
•
•
•
•
SELECT uncompress(test) as test FROM `table` WHERE `compressed` = compress('test')
And the confusion you may have had before about the bz library also known as bzip2 or bz2 depend on what version (I found out the hard way) that was another option I was exploring untill I found out it couldn't compress crc32 hashes. So as I said, if that above code works, that will be the solution to all my endless reverse hashing storage problems.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - MacGyver Fan
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - MacGyver Fan
Some good info here: http://www.mysqlperformanceblog.com/...ance-benefits/
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
It works!
Even though it requires twice as much space on the mysql cache it works perfectly. Thanks for that very usefull code that I could not find anywhere else.
Even though it requires twice as much space on the mysql cache it works perfectly. Thanks for that very usefull code that I could not find anywhere else.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - MacGyver Fan
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - MacGyver Fan
•
•
•
•
It works!
Even though it requires twice as much space on the mysql cache it works perfectly. Thanks for that very usefull code that I could not find anywhere else.
Assuming you're using the default compression, zlib, then you need to cut off the first 4 bytes before you uncompress the data.
The first 4 bytes is reserved for the length of the uncompressed string.
see: http://dev.mysql.com/doc/refman/5.0/...ction_compress
Here if a full example using PDO:
php Syntax (Toggle Plain Text)
<?php /* Connect to an ODBC database using driver invocation */ $dsn = 'mysql:dbname=test;host=localhost'; $user = 'root'; $password = ''; try { $dbh = new PDO($dsn, $user, $password); } catch (PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); } $sql = 'SELECT binary(compressed) AS compressed FROM `compressed` WHERE compress(:test) = compressed '; $sth = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); $sth->execute(array(':test' => 'test')); $row = $sth->fetch(); // compressed result, with first 4 bytes being the length $result = $row['compressed']; // the length of uncompressed string $len = substr($result, 0, 4); // the compressed string $compressed = substr($result, 4, strlen($result)-4); // uncompress the string echo gzuncompress($compressed, intval($len)); // test ?>
Edit:
Here is the structure of the table I used in the example:
PHP Syntax (Toggle Plain Text)
+------------+------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------+------+------+-----+---------+-------+ | value | text | NO | | NULL | | | compressed | blob | NO | | NULL | | +------------+------+------+-----+---------+-------+
And the dump:
PHP Syntax (Toggle Plain Text)
-- -- Database: `test` -- -- -------------------------------------------------------- -- -- Table structure for table `compressed` -- CREATE TABLE IF NOT EXISTS `compressed` ( `value` text COLLATE utf8_unicode_ci NOT NULL, `compressed` blob NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- -- Dumping data for table `compressed` -- INSERT INTO `compressed` (`value`, `compressed`) VALUES ('test', 0x04000000789c2b492d2e0100045d01c1);
Last edited by digital-ether; Sep 18th, 2009 at 1:47 pm.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Similar Threads
- Add compression to my program (C++)
- Best File Compression Software? (Windows Software)
- [basics] LZ(W) compression explanation. (C)
- Help with compression program (C)
Other Threads in the PHP Forum
- Previous Thread: .htaccess for short URL redirection on a subdomain?
- Next Thread: I need to embed stock live charts in website
| Thread Tools | Search this Thread |
add advice array assembly binary c# c++ calling centimeter char class classes cm code compression convert date datetime decimals decode domain drawing ect encode encryption exe feet file filter format function gdi+ generator i/o inches incode inline int java kilometer kioti16 km mail math meter method numbers parameter parse php plotting pointer program py py2exe python random recursion recursive reference return source string text tree url variable vb.net wxpython year







