mysqli multi_query followed by query

2019-05-10 03:38发布

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?

1条回答
我只想做你的唯一
2楼-- · 2019-05-10 04:28

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.

查看更多
登录 后发表回答