简体   繁体   中英

Error in sql syntax value ? but it's showing the value?

the title isn't very specific but I don't know how to make it better. I've got this error in my sql telling me something is wrong but I don't understand why it's wrong, currently using mysql 8.0.24. If you wonder why it looks strange it's because I use it in lua

Sql:

local q = [[SELECT id, hex_id, steam_id, community_id, name, ip, rank FROM users WHERE hex_id = @id;]]
local v = {["id"] = hexId}

Error:

An error happens for query "SELECT id, hex_id, steam_id, community_id, name, ip, rank FROM users WHERE hex_id = ?; : ["steam:*****"]": ER_PARSE_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 'FROM users WHERE hex_id = 'steam:*****'' at line 1

RANK is a keyword in MySQL 8. You need to enclose it inside backticks:

SELECT id, hex_id, steam_id, community_id, name, ip, `rank` FROM users ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM