开发者

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

开发者 https://www.devze.com 2023-03-21 17:47 出处:网络
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
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

精彩评论

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