-1

I have a custom GC Session method set that should delete any old sessions out of my database. Here is the func:

    public function gc($max){
      // Calculate what is to be deemed old
      date_default_timezone_set('America/Chicago');
      $old = time() - $max;

      // Set query
      $this->db->query('DELETE * FROM session WHERE access < :old');

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

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

      // Return False
      return false;
    }

The $max var represents the session.gc_maxlifetime value in my php.ini. Here are the garbage collection settings in my .ini:

session.gc_probability = 1
session.gc_divisor     = 100
session.gc_maxlifetime = 1440

However whenever this function runs, I always get the following Fatal Error:

PHP 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 < 1482965344' at line 1' in /Applications/MAMP/htdocs/demo/DB.php:66

Can't help but feel like I am missing something trivial...Any suggestions?

Jared Garcia
  • 751
  • 1
  • 8
  • 17

2 Answers2

1

You should use:

'DELETE FROM session WHERE access < :old' as your DML string.

Remove the *.

Hicaro
  • 687
  • 2
  • 8
  • 21
0

Your SQL Query is wrong. There is no * between DELETE and FROM. Just use this line:

$this->db->query('DELETE FROM session WHERE access < :old');
gseidel
  • 321
  • 2
  • 9