0

I am trying to execute 2 queries at the same time. I know I can do this using mysqli::multi_query.

But is there any way I can perform a multiple queries using prepared statements?

Below is an example of my query Thanks!

$delete_all_options = "DELETE FROM option_categories WHERE item_id = ?; ";
$delete_all_options .= "DELETE FROM option_names WHERE option_category_id = ?";
$delete_stmt = $db->prepare($delete_all_options);
//Execute statement ......
marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
elrado88
  • 75
  • 2
  • 8

1 Answers1

0

You may want to use transactions. Here's an explanation for using transactions with PDO: http://php.net/manual/en/pdo.transactions.php . Transactions can be used also with the MySQLi extension, by setting MySQLi::autocommit(false) and then committing with MySQLi::commit() (with PHP 5.5+ you can also use MySQLi::begin_transaction() and other methods).

Transactions execute multiple queries "at once" and if one query fails all the transaction is reverted.

ItalyPaleAle
  • 7,016
  • 6
  • 42
  • 66