1

I have this script that stores encrypted sessions inside the database in order to prevent session hijacking.I have definied my own functions for session storing and those are all stored inside the session class.All the functions seem to be working properly but as soon as i run my garbage collector function.It throws me an error stating

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' * FROM sessions WHERE access < 1454859044' at line 1' in C:\wamp\www\session\class.database.php on line 61

Function For Garbage collection :

public function _gc($max){
// Calculate what is to be deemed old
$old = time() - $max;

  $this->db->query('DELETE * FROM sessions WHERE access < :old');
  //Error Possibly occurs on this line
// Set query


// Bind data
$this->db->bind(':old', $old);

// Attempt execution
if($this->db->execute()){
  // Return True
  return true;
}

// Return False
return false;
 }
}

Function for Query Function:

     public function query($query){
        $this->stmt = $this->dbh->prepare($query);
    }

Files :

http://codepad.org/QCfTH5Rh ( Session class file which defines the function to read, write sessions etc.)

http://codepad.org/j3eLaZgd ( Database Class file which defines the functions like query,execute etc.)

chris85
  • 23,846
  • 7
  • 34
  • 51

1 Answers1

1

Your query is incorrect. The delete doesn't take a listing of columns to delete, it deletes the whole row. Try:

DELETE FROM sessions WHERE access < :old
chris85
  • 23,846
  • 7
  • 34
  • 51