简单插入查询返回语法错误
Simple Insert Query Returning Syntax Error
任何人都可以找到我的错误所在,因为我真的很生气
这是我的代码:
$query = 'INSERT INTO mk_pay_wages (u_id, year_month, wage) VALUES (14, "2021-06", 900)';
echo $query . '<br>';
$mysqli->query($query) or die ($mysqli->error);
这是 mySQL table:
最后这是它的输出:
INSERT INTO mk_pay_wages (u_id, year_month, wage) VALUES (14, "2021-06", 900)
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 'year_month, wage) VALUES (14, "2021-06", 900)' at line 1
YEAR_MONTH
是 MySQL 中的保留关键字:
https://dev.mysql.com/doc/refman/5.7/en/keywords.html#keywords-5-7-detailed-Y
只有将保留关键字括在反引号中,您才能将其用作标识符:
INSERT INTO mk_pay_wages (u_id, `year_month`, wage) ...
任何人都可以找到我的错误所在,因为我真的很生气
这是我的代码:
$query = 'INSERT INTO mk_pay_wages (u_id, year_month, wage) VALUES (14, "2021-06", 900)';
echo $query . '<br>';
$mysqli->query($query) or die ($mysqli->error);
这是 mySQL table:
最后这是它的输出:
INSERT INTO mk_pay_wages (u_id, year_month, wage) VALUES (14, "2021-06", 900)
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 'year_month, wage) VALUES (14, "2021-06", 900)' at line 1
YEAR_MONTH
是 MySQL 中的保留关键字:
https://dev.mysql.com/doc/refman/5.7/en/keywords.html#keywords-5-7-detailed-Y
只有将保留关键字括在反引号中,您才能将其用作标识符:
INSERT INTO mk_pay_wages (u_id, `year_month`, wage) ...