PHP PDO:语法错误或访问冲突(帮助)

0 php database pdo prepare

我有PDO的问题,无法找到解决方案:

我的功能:

public static function create($position, $name, $mail, $mailtext, $confirmed, $key, $formid) {
    global $database;

    try {
        $pdo_result = $database->prepare('INSERT INTO Form (Position, Name, Mail, MailText, Confirmed, Key, Form_idForm) VALUES(:Position, :Name, :Mail, :MailText, :Confirmed, :Key, :Form_idForm)');
        $pdo_result->execute(array(
            ':Position' => $position,
            ':Name' => $name,
            ':Mail' => $mail,
            ':MailText' => $mailtext,
            ':Confirmed' => $confirmed,
            ':Key' => $key,
            ':Form_idForm' => $formid
        ));

        return $database->lastInsertId();
    } catch(PDOException $e) {
        Page::error('Error: Message:', $e->getMessage());
    }

    return null;
}
Run Code Online (Sandbox Code Playgroud)

例外: SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法中有错误; 检查与MySQL服务器版本对应的手册,以便在'Key,Form_idForm'附近使用正确的语法VALUES('Position','Name','Mail','MailText','1','keeey',''在第1行

Bjo*_*ern 5

您在字段名称中使用保留字.

尝试在你的INSERT-construct中转义你的-statement,$database->prepare如下所示:

INSERT INTO Form (
    `Position`, `Name`, `Mail`, `MailText`, 
    `Confirmed`, `Key`, `Form_idForm`)  .... 
Run Code Online (Sandbox Code Playgroud)