您好我有这个插入数据的功能:
function add_item($id, $name, $level, $img, $health, $mana, $stamia, $str, $int, $luc, $information, $gold, $tradeable, $faction)
{
if (isset($_SESSION['admin']))
{
global $pdo;
$check = $pdo->prepare("SELECT * FROM items WHERE item_id = :id AND item_name = :name");
$check->execute(array(":id" => $id, ":name" => $name));
/**
* Checking if row doesn't exists
**/
if (!$check->rowCount())
{
$insert = $pdo->prepare
("
INSERT INTO items
(item_id, item_name, item_level, item_thumbnail, date, time, health, mana, stamia, str, int, luc, information, tradeable, faction, price)
VALUES
(:id, :name, :level, :img, CURDATE(), CURTIME(), :health, :mana, :stamia, :str, :int, :luc, :information, :tradeable, :faction, :price)
");
$insert->execute(array
(
":id" => $id,
":name" => $name,
":level" => $level,
":img" => $img,
":health" => $health,
":mana" => $mana,
":stamia" => $stamia,
":str" => $str,
":int" => $int,
":luc" => $luc,
":information" => $information,
":tradeable" => $tradeable,
":faction" => $faction,
":price" => $gold
));
}
}
但在处理完毕后,我收到此错误:
SQLSTATE[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 'int, luc, information, tradeable, faction, price) VALUES ('34434', 'dre' at line 2
Everythig似乎是正确的?那里有什么问题? 我看不出查询语法有任何错误。
感谢。
答案 0 :(得分:3)
int
是this list of reserved keywords中的关键字;所以你不能在查询中使用它;尝试用反引号包装它:
INSERT INTO items (item_id, ..., `int`, ...)
答案 1 :(得分:0)
在mysql中,int
是保留字,因此如果您有一个名为int
的列,则需要反引它:..., `int`, ...