MySQL COMPRESS与PHP gzcompress [英] MySQL COMPRESS vs PHP gzcompress

查看:57
本文介绍了MySQL COMPRESS与PHP gzcompress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个PHP应用程序,该应用程序需要将大量文本存储在MySQL数据库中.遇到过PHP的 gzcompress 和MySQL的 COMPRESS 可能是减小存储数据大小的方法.

I am developing a PHP application where large amounts of text needs to be stored in a MySQL database. Have come across PHP's gzcompress and MySQL's COMPRESS functions as possible ways of reducing the stored data size.

这两个功能之间有什么区别?

What is the difference, if any, between these two functions?

(我目前的想法是 gzcompress 似乎更灵活,因为它允许指定压缩级别,而 COMPRESS 可能实现起来更简单,解耦更好?性能也是一个重要的考虑因素.)

(My current thoughts are gzcompress seems more flexible in that it allows the compression level to be specified, whereas COMPRESS may be a bit simpler to implement and better decoupling? Performance is also a big consideration.)

推荐答案

这两种方法或多或少是同一件事,实际上您可以将它们混合使用:在php中压缩,在MySQL中解压缩,反之亦然.

The two methods are more or less the same thing, in fact you can mix them: compress in php and uncompress in MySQL and vice versa.

要在MySQL中压缩:

To compress in MySQL:

INSERT INTO table (data) VALUE(COMPRESS(data));

要在PHP中压缩:

$compressed_data = "\x1f\x8b\x08\x00".gzcompress($uncompressed_data);

要在MySQL中解压缩:

To uncompress in MySQL:

SELECT UNCOMPRESS(data) FROM table;

要在PHP中解压缩:

$uncompressed_data = gzuncompress(substr($compressed_data, 4));

另一种选择是使用MySQL表压缩

只需要配置,然后透明.

It only require configuration and then it is transparent.

这篇关于MySQL COMPRESS与PHP gzcompress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆