SQL
Table for storing user sessions:
CREATE TABLE sessions (
user_id INT,
expires TIMESTAMP
);
To create a session:
INSERT INTO sessions (user_id, expires) VALUES (:user_id,
CURRENT_TIMESTAMP + INTERVAL '+15 minutes');
To get a session:
SELECT * FROM sessions WHERE user_id = :user_id AND
CURRENT_TIMESTAMP < expires;
Questions
Is this portable SQL?
Will this work with any database accessible through the PHP PDO extension (excluding SQLite)?
Is this correct in different time zones? Through daylight saving time?
Any mixing problem CURRENT_TIMESTAMP(which includes timezone information) with a column TIMESTAMP(what's wrong)?
source
share