您在PDO中的SQL语法中有错误

时间:2018-08-08 09:39:55

标签: mysql pdo

我试图修复3个小时的sql问题,但找不到能破坏代码的小东西。

错误:

  

您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册以获取正确的语法,以在第1行的'order,image,category_id)VALUES('test','test','

test'附近使用

查询:所有变量都是发送的帖子字段。

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>, צרו קשר עם המנהל");
}       

1 个答案:

答案 0 :(得分:0)

grave通常被称为“反引号”,MySQL用来逃避MySQL保留字。

@Mat已经说过他的评论,说您在语句中使用了保留字,说明了为什么它会引发错误并且是“ order”,因此,如果您使用这种类型的保留字,则必须以下面的方式编写查询。

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

尽管我用于每列,但并不需要,您只能将其用于“订单”列