Serialize
(PHP3 >= 3.0.5, PHP4)
Serialize---&http://www.aliyun.com/zixun/aggregation/37954.html ">nbsp; A representation that produces a stored value
Syntax: String serialize (mixed value)
Description:
Serialize () returns a string containing the byte-stream, represented by value, that can be stored anywhere.
This can be used to store or pass PHP values without losing their form and structure.
Using Unserialize () enables the serialized string to become the original PHP value again. Serialize () can handle the form of integer, double, string, array (faceted), object (the properties of the object will be serialized, but the method will be lose)
Example:
<?php
$session _data contains a multi-dimensional array with session
Information for the current user. We use serialize () to store
It in a database at the end of the request.
$conn = Odbc_connect ("WebDB", "PHP", "chicken");
$stmt = Odbc_prepare ($conn, "UPDATE sessions SET data =? WHERE id =? ");
$sqldata = Array (serialize ($session _data), $PHP _auth_user);
if (!odbc_execute ($stmt, & $sqldata)) {
$stmt = Odbc_prepare ($conn, INSERT into sessions (ID, data) VALUES (?,?));
if (!odbc_execute ($stmt, & $sqldata)) {
/* something went wrong. Bitch, whine and moan. */
}
}
?>