1
2 // Here, we use unserialize() to load session data from a database
3 // into $session_data. This example complements the one described
4 // with serialize().
5
6 $conn = odbc_connect ("webdb", "php", "chicken");
7 $stmt = odbc_prepare ($conn, "SELECT data FROM sessions WHERE id = ?");
8 $sqldata = array ($PHP_AUTH_USER);
9 if (!odbc_execute ($stmt, &$sqldata) || !odbc_fetch_into ($stmt, &$tmp)) {
10 // if the execute or fetch fails, initialize to empty array
11 $session_data = array();
12 } else {
13 // we should now have the serialized data in $tmp[0].
14 $session_data = unserialize ($tmp[0]);
15 if (!is_array ($session_data)) {
16 // something went wrong, initialize to empty array
17 $session_data = array();
18 }
19 }
20 |