mysqli_use_result()和并发 [英] mysqli_use_result() and concurrency

查看:113
本文介绍了mysqli_use_result()和并发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 mysqli_use_result

如果在客户端执行了大量处理,则不应使用mysqli_use_result(),因为这将占用服务器并阻止其他线程更新正在从中获取数据的任何表.

One should not use mysqli_use_result() if a lot of processing on the client side is performed, since this will tie up the server and prevent other threads from updating any tables from which the data is being fetched.

这仅与myISAM表有关还是与InnoDB有关?

Does this only pertain to myISAM tables or also for InnoDB?

推荐答案

只需检查:MyISAM锁定,InnoDB不锁定:

Just checked: MyISAM locks, InnoDB doesn't lock:

<?php
        $db = new mysqli() or die ("Cannot connect: " . mysqli_connect_error() . "\n");
        $query = "SELECT * FROM mytable";
        $db->real_query($query) or die ("Cannot fetch: $db->error\n");
        $result = $db->use_result() or die ("Cannot use result: $db->error\n");
        while($row = $result->fetch_row()) {
                print join("\t", $row) . "\n";
                usleep(1000000);
        }
?>

此锁定:

UPDATE mytable /* isam */ SET myvalue = 'test' WHERE id = 100

这不是:

UPDATE mytable /* innodb */ SET myvalue = 'test' WHERE id = 100

这篇关于mysqli_use_result()和并发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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