Yes, mysqli:multi_query()
does send the SQL in one go to the server. This operation is asynchronous. PHP does not wait for MySQL to perform the full SQL. As soon as mysqli gets a single result, the control is given back to PHP script while the execution of the SQL continues on the MySQL server.
However, to get the results you need to block PHP script and ask MySQL to provide the result. This is why you need to call next_result()
4 times if you expect to receive 5 results. Each call does make a new trip to the server to ask for the results, which might already be ready and waiting to be fetched or not.
In practice, you might end up making more than 5 trips to the MySQL server. It's worth pointing out that this is not going to improve the performance of your PHP script on its own. Unless you have some very good reason to execute SQL in bulk on the MySQL server do not use mysqli::multi_query()
. Stick to using prepared statements.