I have written a few classes, but they have been fairly basic. I am now trying to write a class that will, upon instantiation, check for a session; if the session does not exist, it is created. This class does not work so far and I wondered if I could get some pointers.
class PrevNext {
//call the constructor check for an existing session and create one if non exist
function PrevNext() {
if(!$_SESSION['peopleIndex']) {
$this->db = DB::connect($this->dsn);
if(DB::isError($this->dsn)) {
die($this->db->getMessage());
$this->result = $this->db->getAll("select people_id, lname from people_info order by lname asc");
if(DB::isError($this->result)) {
die($this->result->getMessage());
}
$_SESSION['peopleIndex'] = $this->result;
}
}
}
}
The problem is that the session is not being written. Is there something that needs to be done because the session is being written in a class?