Database Reference
In-Depth Information
name, so both arguments can be ignored. The function therefore does nothing but open
a connection to MySQL:
function mysql_sess_open ( $save_path , $sess_name )
{
global $mysql_sess_dbh ;
# open connection to MySQL if it's not already open
if ( $mysql_sess_dbh === NULL )
{
try
{
$mysql_sess_dbh = Cookbook :: connect ();
}
catch ( PDOException $e )
{
$mysql_sess_dbh = NULL ;
return ( FALSE );
}
}
return ( TRUE );
}
Closing a session. The close handler checks whether a connection to MySQL is open and
closes it if so:
function mysql_sess_close ()
{
global $mysql_sess_dbh ;
if ( $mysql_sess_dbh !== NULL ) # close connection if it's open
$mysql_sess_dbh = NULL ;
return ( TRUE );
}
Reading session data. The mysql_sess_read() function uses the session ID to look up
the data for the corresponding session record and returns it. It returns the empty string
if no such record exists, or FALSE if an error occurs:
function mysql_sess_read ( $sess_id )
{
global $mysql_sess_dbh ;
try
{
$stmt = "SELECT data FROM php_session WHERE id = ?" ;
$sth = $mysql_sess_dbh -> prepare ( $stmt );
$sth -> execute ( array ( $sess_id ));
list ( $data ) = $sth -> fetch ( PDO :: FETCH_NUM );
if ( isset ( $data ))
return ( $data );
Search WWH ::




Custom Search