7

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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

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.
@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.
@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^^

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.