Mysql查询奇怪失败

时间:2013-07-11 13:59:49

标签: php mysql

当我添加key列时,此查询给我一个错误,任何帮助?

usernameproduct是复合主键,以防万一。

mysql> select * from sw_product_session where username='admin';
+----------+----------+------------+----------------------------+
| username | product  | expire     | key                        |
+----------+----------+------------+----------------------------+
| admin    | printbox | 1373550885 | 2ijm77cpnfc7miktasopkik2q2 |
+----------+----------+------------+----------------------------+
1 row in set (0.00 sec)

mysql> select * from sw_product_session where username='admin' AND product='printbox';
+----------+----------+------------+----------------------------+
| username | product  | expire     | key                        |
+----------+----------+------------+----------------------------+
| admin    | printbox | 1373550885 | 2ijm77cpnfc7miktasopkik2q2 |
+----------+----------+------------+----------------------------+
1 row in set (0.00 sec)

mysql> select * from sw_product_session where username='admin' AND product='printbox' AND key='2ijm77cpnfc7miktasopkik2q2';
ERROR 1064 (42000): 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 'key='2ijm77cpnfc7miktasopkik2q2'' at line 1

1 个答案:

答案 0 :(得分:8)

您需要记住,任何reserved words都需要转义:

AND `key`='...'