Why Can't Two mysqli Queries Be Run Simultaneously?
In MySQL, executing multiple queries in a single call requires the use of mysqli_multi_query(). Attempting to execute two queries using mysqli_query() will result in the second query failing.
Solution: mysqli_multi_query()
To resolve this issue, the correct method to use is mysqli_multi_query(). It takes a string of queries separated by semicolons as its input.
Example:
$mysqli = new mysqli($host, $user, $password, $database); // Queries to be executed $query = "INSERT INTO images (project_id, user_id, image_name, ...) VALUES (...);"; $query .= "INSERT INTO images_history (project_id, user_id, image_name, ...) VALUES (...);"; // Execute queries using mysqli_multi_query() $result = mysqli_multi_query($mysqli, $query); // Handle results if ($result) { // Process results using mysqli_store_result() and mysqli_next_result() } else { // Handle error (if any) }
Note:
The above is the detailed content of Why Can't I Run Two `mysqli_query()` Calls Simultaneously in MySQL?. For more information, please follow other related articles on the PHP Chinese website!