Hi,
I am storing the session variables in my DB (mySQL) and to start with I used the mysql functions for DB access and when I switched to using PDO interface my DB is not updated.
Here follows my conversion from mysql syntax to PDO
// The open function
// before:
function _open()
{
if ($result = mysql_connect('localhost', '<USER>', '<PASSWORD>'))
{
return mysql_select_db('<DB>');
}
return FALSE;
}
// after:
function _open()
{
// set global DB object... why????
global $_dbh;
// Establish connection to the mySQL server
try
{
$_dbh = new PDO('mysql:host=localhost;dbname=<DB>', '<USER>', '<PASSWORD>');
return TRUE;
}
catch (PDOException $e)
{
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
}
// the write function
// before:
function _write($id, $data)
{
$access = time();
$id = mysql_real_escape_string($id);
$access = mysql_real_escape_string($access);
$data = mysql_real_escape_string($data);
$sql = "REPLACE
INTO sessions
VALUES ('$id', '$access', '$data')";
return mysql_query($sql);
}
// after:
function _write($id, $data)
{
// set global DB object... why????
global $_dbh;
$access = time();
// Prepare statement
$stmt = $_dbh->prepare("REPLACE INTO sessions VALUES (:id, :access, :data)");
$stmt->bindParam(':id', $id);
$stmt->bindParam(':access', $access);
$stmt->bindParam(':data', $data);
return $stmt->execute();
}
If you need to see the other functions declared in session_set_save_handler i can post them as well.
Note, I have never used PDO before and I am also a newbie in this environment.