Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unbuffered query with MySQLi?

Are MySQLi queries unbuffered? If not, is there a way to do an unbuffered query, as with the non-MySQLi mysql_unbuffered_query()?

like image 704
ceejayoz Avatar asked Dec 30 '09 19:12

ceejayoz


People also ask

What is unbuffered database query?

Unbuffered queries can also be referred to as "use result". Following these characteristics buffered queries should be used in cases where you expect only a limited result set or need to know the amount of returned rows before reading all rows. Unbuffered mode should be used when you expect larger results.

What will unbuffered query do?

Unbuffered MySQL queries execute the query and then return a resource that points to the result set. This uses less memory, and allows MySQL to continue executing the query as the result set is used. It also increases load on the server.

What is Mysqli_query () used for?

Definition and Usage The query() / mysqli_query() function performs a query against a database.

What value does Mysqli_query return?

Return Values ¶ For successful queries which produce a result set, such as SELECT, SHOW, DESCRIBE or EXPLAIN , mysqli_query() will return a mysqli_result object. For other successful queries, mysqli_query() will return true .


2 Answers

MindStalker is right but maybe the easiest way is the one shown in the PHP manual
http://php.net/manual/en/mysqlinfo.concepts.buffering.php

Passing the MYSQLI_USE_RESULT constant as the resultmode argument, you can set mysqli_query to work as mysql_unbuffered_query

<?php
$mysqli  = new mysqli("localhost", "my_user", "my_password", "world");
$uresult = $mysqli->query("SELECT Name FROM City", MYSQLI_USE_RESULT);

if ($uresult) {
   while ($row = $uresult->fetch_assoc()) {
       echo $row['Name'] . PHP_EOL;
   }
}
$uresult->close();
?>
like image 166
nulll Avatar answered Oct 11 '22 21:10

nulll


mysqli_real_query() followed by mysqli_use_result()

like image 42
MindStalker Avatar answered Oct 11 '22 22:10

MindStalker