mysql语句不起作用

时间:2012-06-04 15:00:46

标签: mysql

我正在尝试创建一个安全的会话管理,其中每个用户都获得一个哈希值,如果用户登录到其他位置,那么它会检查用户是否具有最近登录的哈希值。这样,如果用户忘记注销,系统将为其注销帐户。这是我写的sql语句,它给了我这个错误。有人可以告诉我为什么吗?

谢谢

"SELECT * FROM 'v_pos_user_session WHERE userID='$userID' AND hash='$hash' AND admin='0' time=(SELECT max(time) FROM v_pos_user_session WHERE userID='$userID' AND admin='0')"

QLSTATE[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 'time=(SELECT max(time) FROM v_pos_user_session WHERE userID='6' AND admin='0')' at line 1

1 个答案:

答案 0 :(得分:6)

你必须用反引号逃脱time并忘记and

SELECT * FROM v_pos_user_session 
WHERE userID='$userID' 
AND hash='$hash' 
AND admin='0' 
and `time`=(SELECT max(time) FROM v_pos_user_session 
            WHERE userID='$userID' AND admin='0')

您在'

之前留下了不必要的v_pos_user_session