开发者

Is there a more efficient way to save an Array to SQL than PHP function serialize()? [duplicate]

This question already has answers here: 开发者_运维百科 Closed 11 years ago.

Possible Duplicate:

An efficient way to save an Array and its Keys to a database

Is there maybe an serialize() equivalent which returns binary?

Saving data as strings is inefficient in both ways: inefficient in a manner of performance and memory. Is there a function to return the pure data from the RAM and accordingly a function to read it back?


If all you are trying to do is get a more compact representation of the serialized string, e.g., one that uses less space than plain serialize(), you might just use gzdeflate() to compress the plain-text output:

$data = gzdeflate(serialize($some_array));
// Store in database...

// To restore the array: Get $data from the database, then:
$array = unserialize(gzinflate($data));

Instead of gzdeflate()/gzinflate(), you can also use gzcompress()/gzuncompress(), but these produce slightly larger strings as they include additional metadata such as a checksum.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜