?php / / Here, we use unserialize() to load session data to the / / $session_data array from the string selected from a database. / / This example complements the one described with serialize(). $conn = odbc_connect ("webdb", "php", "chicken"); $stmt = odbc_prepare ($conn, "SELECT data FROM sessions WHERE id = ?"); $sqldata = array ($PHP_AUTH_USER); if (!odbc_execute ($stmt, $sqldata) _BAR_ _BAR_ !odbc_fetch_into ($stmt, $tmp)) {/ / if the execute or fetch fails, initialize to empty array $session_data = array();} else {/ / we should now have the serialized data in $tmp[0]. $session_data = unserialize ($tmp[0]); if (!is_array ($session_data)) {/ / something went wrong, initialize to empty array $session_data = array();}}?
Cet exemple complète / / celui fourni avec serialize(). $conn = odbc_connect ("webdb", "php", "chicken"); $stmt = odbc_prepare ($conn, "SELECT data FROM sessions WHERE id = ?"); $sqldata = array ($PHP_AUTH_USER); if (!odbc_execute ($stmt, $sqldata) _BAR_ _BAR_ !odbc_fetch_into ($stmt, $tmp)) {/ / si la préparation ou la lecture échoue, on crée un tableau vide $session_data = array();} else {/ / les données sauvées sont dasn $tmp[0]. $session_data = unserialize ($tmp[0]); if (!is_array ($session_data)) {/ / Erreur... initialisation à tableau vide $session_data = array();}}?