【问题标题】:INSERT INTO SQL Heredoc correct syntaxINSERT INTO SQL Heredoc 正确语法
【发布时间】:2013-11-01 16:36:39
【问题描述】:

我正在尝试将 heredoc 语法与 INSERT INTO MySQL 命令一起使用到数据库中。

我面临的问题是变量$tPerson_SQLinsert,它是一个查询。

这是我的代码:

$tPerson_SQLinsert = <<<SQL
    INSERT INTO tPerson (Salutation, FirstName, LastName, Tel, companyID)
    VALUES ("$Salutation", "$FirstName", "$LastName", "$Tel", "$companyID")
    SQL;

嗯,这个语法可能有问题。

因为我收到了这个 Parse 错误:

 Parse error: syntax error, unexpected end of file in F:\wamp\www\forms\personInsert.php on line 83

这只是 php ?&gt; 的结束标记。

heredoc 的正确语法是什么?

谢谢。

【问题讨论】:

    标签: php mysql heredoc


    【解决方案1】:

    当你像这样格式化它时它会起作用:

    $tPerson_SQLinsert = <<<SQL
        INSERT INTO tPerson (Salutation, FirstName, LastName, Tel, companyID)
        VALUES ("$Salutation", "$FirstName", "$LastName", "$Tel", "$companyID")
    SQL;
    

    即最后的分隔符应该从第 1 列开始。

    请参阅文档(在警告块中): https://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多