mysqli_use_result() and concurrency

做~自己de王妃 提交于 2019-12-11 14:47:45

问题


According to the documentation at 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.

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


回答1:


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);
        }
?>

This locks:

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

This doesn't:

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


来源:https://stackoverflow.com/questions/591936/mysqli-use-result-and-concurrency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!