phpmysqldatabasemysqlimysqli-multi-query

mysqli multi_query followed by query


I am currently doing the following:

$mysqli = new mysqli($server, $username, $password, $database);

$mysqli->multi_query($multiUpdates);
while ($mysqli->next_result()) {;} // Flushing results of multi_queries
$mysqli->query($sqlInserts);

Is there a faster way to dump the results?

I do not need them and just want to run the next query however I get the error:

Commands out of sync; you can't run this command now

Problem is the while ($mysqli->next_result()) {;} takes about 2 seconds which is a waste for something I don't want.

Any better solutions out there?


Solution

  • Found a faster solution which saves about 2-3 seconds when updating 500 records and inserting 500 records.

    function newSQL() {
        global $server, $username, $password, $database;
        $con = new mysqli($server, $username, $password, $database);
        return $con;
    }
    
    $mysqli = newSQL();
    $mysqli->multi_query($multiUpdates);
    $mysqli->close();
    
    $mysqli = newSQL();
    $mysqli->query($sqlInserts);
    $mysqli->close();
    

    Not sure how practical it is but works well for speed.