Database Reference
In-Depth Information
}
catch
(
PDOException
$e
) {
/* do nothing */
}
return
(
""
);
}
Writing session data.
mysql_sess_write()
creates a new record if there is none for the
session yet, or replaces the existing record if there is one:
function
mysql_sess_write
(
$sess_id
,
$sess_data
)
{
global
$mysql_sess_dbh
;
try
{
$stmt
=
"REPLACE php_session (id, data) VALUES(?,?)"
;
$sth
=
$mysql_sess_dbh
->
prepare
(
$stmt
);
$sth
->
execute
(
array
(
$sess_id
,
$sess_data
));
return
(
TRUE
);
}
catch
(
PDOException
$e
)
{
return
(
FALSE
);
}
}
Destroying a session.
When a session is no longer needed,
mysql_sess_destroy()
re‐
moves the corresponding record:
function
mysql_sess_destroy
(
$sess_id
)
{
global
$mysql_sess_dbh
;
try
{
$stmt
=
"DELETE FROM php_session WHERE id = ?"
;
$sth
=
$mysql_sess_dbh
->
prepare
(
$stmt
);
$sth
->
execute
(
array
(
$sess_id
));
return
(
TRUE
);
}
catch
(
PDOException
$e
)
{
return
(
FALSE
);
}
}
Performing garbage collection.
The
TIMESTAMP
column
update_time
in each session re‐
cord indicates when the session was last updated.
mysql_sess_gc()
uses this value to
implement garbage collection. The argument
$sess_maxlife
specifies how old sessions
can be (in seconds). Older sessions are considered expired and candidates for removal,