I'm trying to modify a script that stores my session data in a database rather than the default but I'm having a bit of trouble as I keep getting the error above. It says I'm getting the error on lines 176 and 201.
Here is the function inside the sessionPdo class
public function _write($id, $sessionData)
{
$session = $this->fetchSession($id); // line 176
if( $session === false ) {
$stmt = $this->db->prepare('INSERT INTO sessions (id, data, unixtime) VALUES (:id, :data, :time)');
} else {
$stmt = $this->db->prepare('UPDATE sessions SET data = :data, unixtime = :time WHERE id = :id');
}
$stmt->execute( array(
':id' => $id,
':data' => $sessionData,
':time' => time()
));
if( $this->transaction ) {
$this->db->commit();
}
}
And here is the fetchSession method in case it helps.
public function fetchSession($id)
{
$stmt = $this->db->prepare('SELECT id, data FROM sessions WHERE id = :id AND unixtime > :unixtime');
$stmt->execute( array(':id' => $id, ':unixtime' => ( time() - (int) ini_get('session.gc_maxlifetime') ) ) );
$sessions = $stmt->fetchAll();
if( $this->transaction ) {
$this->db->commit();
}
return empty($sessions) ? false : $sessions[0] ;
}
I've struggled to find what I'm doing wrong as all the solutions I've found are because the programmer tried to call $this from outside of the class. I'm new to PDO so thanks in advance for any help you can give.
_write()
in the first place. If that code calls _write() outside of the object's scope, you'll get this errors as $this won't be defined inside _write() in that case. – Marc B Oct 24 '11 at 18:38176
and201
? – Jonathan Spooner Oct 24 '11 at 18:42_write()
statically anywhere?sessionPdo::_write(.....)
? Try addingprint_r(debug_backtrace())
right before line 176 to see what's calling what. – alexantd Oct 24 '11 at 18:42