mysqli中的multi_query后跟查询 [英] mysqli multi_query followed by query

查看:220
本文介绍了mysqli中的multi_query后跟查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在进行以下操作:

  $ mysqli = new mysqli($ server,$ username,$ password,$数据库); 

$ mysqli-> multi_query($ multipleUpdates);
while($ mysqli-> next_result()){;} //清除multi_queries的结果
$ mysqli-> query($ sqlInserts);有没有更快的方法来转储结果?








我不需要它们,只是想运行下一个查询,但是我得到错误:


命令不同步;您现在无法运行此命令


问题是 while($ mysqli-> next_result )



有更好的解决方案吗?

p>

解决方案

找到更快的解决方案,在更新500条记录和插入500条记录时可节省大约2-3秒。

  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();

不知道这是多么实用,但速度很快。


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?

解决方案

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.

这篇关于mysqli中的multi_query后跟查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆