RE: [PHP-DB] serialize/unserialize vs. implode/explode for storing array data in MySQL
| From: | Troy Settle | Date: | Mon, 09 Oct 2000 22:40:18 +0000 |
| Subject: | RE: [PHP-DB] serialize/unserialize vs. implode/explode for storing array data in MySQL | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-3442@lists.php.net to get a copy of this message | ||
If you're dealing with a simple numeric array, you can get away with
implode/explode. I'd use this for something like /etc/passwd:
user:password:uid:gid:etc...
But, for an array that I reference with keys, I'd use serialize:
$user[name] = "Foo Bar";
$user[address] = "123 Any Street";
$user[phone] = "212.555.1212";
Serialization is also very good for storing an array of objects, each with
multiple values:
$passwd["root"]->uid = 0;
$passwd["root"]->gecos = "Super User";
...
$passwd["www"]->uid = 80;
$passwd["www"]->gecos = "Web User";
And yes... I've had a few applications where it made sense to use arrays of
objects for storing and manipulating various bits information.
Run this little bit of code and compare:
<?
$this[one] = "test";
$this[two] = "foo";
$this[three] = "bar";
echo implode($this,":") . "<P>" . serialize($this);
?>
You'll note that with implode(), you can't recover the keys with an
explode();
HTH,
--
Troy Settle
Pulaski Networks
540.994.4254
It's always a long day, 86400 doesn't fit into a short
> -----Original Message-----
> From: John Guynn [mailto:John.Guynn@telescan.com]
> Sent: Monday, October 09, 2000 6:16 PM
> To: Php-Db (E-mail)
> Subject: [PHP-DB] serialize/unserialize vs. implode/explode for storing
> array data in MySQL
>
>
> What are the pros and cons of using serialize/unserialize vs.
> implode/explode for storing array data in a MySQL database? It
> looks to me
> that the serialize functions will use more space and requires addslashes()
> but is it faster/better somehow?
>
> John Guynn
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> For additional commands, e-mail: php-db-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>
>