Is it possible to execute a single query once the multi-query is fully executed in PHP/MYSQL? Actually, I want to insert a record in a table once the multi-query is fully executed.
public function create_tables($data)
{
$email = $data['email'];
$name = $data['name'];
$storepassword = $data['storepassword'];
$created_date = date('Y/m/d H:i:s');
// Connect to the database
$mysqli = new mysqli($data['hostname'], $data['username'], $data['password'], $data['database']);
// Check for errors
if (mysqli_connect_errno()) {
return false;
}
// Open the default SQL file
$query = file_get_contents('assets/install.sql');
// Execute a multi query
$mysqli->multi_query($query);
$insert = "INSERT INTO `users` (`fullname`, `email`, `password`, `role_id`, `outlet_id`, `created_user_id`, `created_datetime`, `updated_user_id`, `updated_datetime`, `status`) VALUES
('$name', '$email', '$storepassword', 1, 0, 1, '$created_date', 1, '$created_date', 1)";
$mysqli->query($insert);
// Close the connection
$mysqli->close();
return true;
}
add this after the mutli_query
while (mysqli->next_result()){
//do nothing
}
this will cause the execution to loop through the multi_query results thus forcing the script to wait until the multi_query is fully processed before moving on to the next part of the script.
another approach would be to include the final query at the end of and as part of the multi_query