Why error occurs when I send multiple queries into mysqli_query?

前端 未结 1 1319
北恋
北恋 2020-12-06 23:58

The same request in the Adminer has no errors, but in php is

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB

相关标签:
1条回答
  • 2020-12-07 00:42

    You are supposed to run your queries with separate API calls.

    $DB->query("INSERT INTO ...");
    $DB->query("SET @lastID = LAST_INSERT_ID()");
    $DB->query("INSERT INTO ...");
    

    note that you don't actually need the second query here as LAST_INSERT_ID() can be used directly.

    Besides, you should never use a function named "HTML speacial chars" for any database interaction. You have to use prepared statements instead.

    Note that a suggestion to use multi_query is unjustified and misleading, causing a lot of problems.

    0 讨论(0)
提交回复
热议问题