I wanted to know if it is possible to prepare multiple statements for MySQLi multi_query?
1 Answer
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.
3 Comments
Fernando Silva
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.
Pavel V.
@FernandoSilva: I use transactions for this - see this answer for this specific problem and this question and its answers (not only the first one) for transactions.
Fernando Silva
@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^^