使用 where field='string' 查询 select 时出现 MySQLi 错误
MySQLi error on select query with where field='string'
我刚搬到 mySQL 8,之前在 mySQL 5 中工作的查询有错误。
我可以让查询在没有字符串匹配部分的情况下工作,它只匹配一个整数字段,但是当我添加字符串部分时它出错了。
查询:select * from crew where webvisible = 1 and active = 1 and rank = 'member'
Error: 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 '= 'member'' at line 1
我需要根据不同字符串值的rank字段查询,如:会员或会员申请者,或偷渡者等
rank
是 MySQL 8+ 中的 reserved word。您需要将其括在反引号中,即
select * from crew where webvisible = 1 and active = 1 and `rank` = 'member'
我刚搬到 mySQL 8,之前在 mySQL 5 中工作的查询有错误。
我可以让查询在没有字符串匹配部分的情况下工作,它只匹配一个整数字段,但是当我添加字符串部分时它出错了。
查询:select * from crew where webvisible = 1 and active = 1 and rank = 'member'
Error: 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 '= 'member'' at line 1
我需要根据不同字符串值的rank字段查询,如:会员或会员申请者,或偷渡者等
rank
是 MySQL 8+ 中的 reserved word。您需要将其括在反引号中,即
select * from crew where webvisible = 1 and active = 1 and `rank` = 'member'