7

I wanted to know if it is possible to prepare multiple statements for MySQLi multi_query?

MPelletier
  • 16,256
  • 15
  • 86
  • 137
ATLChris
  • 3,198
  • 7
  • 39
  • 65

1 Answers1

8

No.

mysqli::multi_query takes a query string as its argument, not a prepared statement.

mysql::prepare can only prepare a single statement:

The query must consist of a single SQL statement.

lonesomeday
  • 233,373
  • 50
  • 316
  • 318
  • I've got a question. If a prepared statement is a best practice to avoid SQL Injection, how would you perform multiple INSERTS on multiple tables, maintaining the benefits of prepared statements? Would you break each SQL statement into single prepared statements and just cascade them at the database or is there a one-hit solution? I just need some term or expression I can google and learn about. – Fernando Silva Apr 11 '14 at 21:16
  • 1
    @FernandoSilva: I use transactions for this - see [this answer](http://stackoverflow.com/a/11635064/1801588) for this specific problem and [this question and its answers](http://stackoverflow.com/q/12091971/1801588) (not only the first one) for transactions. – Pavel V. Jan 29 '15 at 07:59
  • @PavelV. Thanks, just read up on what you mentioned, that would do the trick for me. I eventually bumped into transactions without even knowing that's what it was called. Thanks once again^^ – Fernando Silva Jan 30 '15 at 00:00