pdo中的sql语法有错误

hgncfbus  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(300)

我试图解决我的sql问题3个小时,我找不到的小东西,破坏我的代码。
错误:
sql语法有错误;请查看与您的mysql服务器版本对应的手册,以了解在第1行中使用“order,image,category\u id)values('test'、'test'、'test'附近的正确语法
查询:所有变量都是发送的post字段。

try {
    $statement = $link->prepare("INSERT INTO `info_pages` (name, title, text, img_credits, meta_title, meta_keywords, order, image, category_id) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)");
    $statement->execute(array($main_title, $side_title, $content, $img_credits, $meta_title, $meta_keywords, $order, $image, $category_id));
    //echo $BNL->msg("הדף <b>{$main_title}</b> נוצר בהצלה, הנך מועבר...", true);
    //echo $BNL->MoveTo($url."index.php?page=info_pages",1);
    if (!$statement->execute()) {
        print_r($statement->errorInfo());
    }
} catch(PDOException $e){
    echo $BNL->msg("<b>שגיאה</b>, צרו קשר עם המנהל");
}
lx0bsm1f

lx0bsm1f1#

grave通常被称为“backtick”,mysql使用它来转义mysql保留字。
@mat已经说了他的评论,你在你的语句中使用了reserve word,这就是为什么抛出错误的原因,也就是“order”,所以如果你使用这种类型的reserve word,你必须在下面写下你的查询。

("INSERT INTO `info_pages`
        (`name`,
         `title`,
         `text`,
         `img_credits`,
         `meta_title`,
         `meta_keywords`,
         `order`,
         `image`,
         `category_id`)
          VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)");

虽然我用在每一列,但不需要,你可以用它只为“顺序”列

相关问题