note 110044 added to mysqli.use-result
| From: | Anonymous | Date: | Fri, 14 Sep 2012 05:30:41 +0000 |
| Subject: | note 110044 added to mysqli.use-result | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-190754@lists.php.net to get a copy of this message | ||
> 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.
Another way of understanding the "blocking" behavior of this "use_result" method
is that by using this method (or the MYSQLI_USE_RESULT flag on the "query" method), if
attempting to run a second query of any kind - updates, inserts, selects, or other - while still
working with these first results, the second query will fail. Checking mysqli->error, you should
get a "Commands out of sync" error on the second query call.
However, if you use the "store_result" method (or the default MYSQLI_STORE_RESULT flag on
the "query" method) instead, the second query will execute just fine.
Just to demonstrate this "blocking" behavior of this "use_result" method, the
second query on line 7 below would otherwise fail if you instead used "use_result" on line
3:
<?php
$mysqli->real_query('SELECT * FROM
test');
$query = $mysqli->store_result();
while ($row = $query->fetch_assoc()) {
$id = (int) $row['id'];
$query2 = $mysqli->query("UPDATE test SET label = md5(rand())
WHERE id = $id");
}
?>
----
Server IP: 192.41.42.26
Probable Submitter: 65.36.72.169
----
Manual Page -- http://www.php.net/manual/en/mysqli.use-result.php
Edit -- https://master.php.net/note/edit/110044
Del: integrated -- https://master.php.net/note/delete/110044/integrated
Del: useless -- https://master.php.net/note/delete/110044/useless
Del: bad code -- https://master.php.net/note/delete/110044/bad+code
Del: spam -- https://master.php.net/note/delete/110044/spam
Del: non-english -- https://master.php.net/note/delete/110044/non-english
Del: in docs -- https://master.php.net/note/delete/110044/in+docs
Del: other reasons-- https://master.php.net/note/delete/110044
Reject -- https://master.php.net/note/reject/110044
Search -- https://master.php.net/manage/user-notes.php