Are MySQLi queries unbuffered? If not, is there a way to do an unbuffered query, as with the non-MySQLi mysql_unbuffered_query()
?
Asked
Active
Viewed 1.3k times
14
-
Do you mean that the query is not buffered, or that the response set is unbuffered? *Why* would unbuffered be advantageous? – wallyk Dec 30 '09 at 19:45
-
3The response set. Per the docs for `mysql_unbuffered_query`: "This saves a considerable amount of memory with SQL queries that produce large result sets, and you can start working on the result set immediately after the first row has been retrieved as you don't have to wait until the complete SQL query has been performed." – ceejayoz Dec 30 '09 at 19:48
-
Ah! Very good. I guess I've never faced moving a lot of data through a MYSQL connection. – wallyk Dec 30 '09 at 19:53
3 Answers
12
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();
?>

nulll
- 1,465
- 1
- 17
- 28
-4
it works for me
$uresult = $mysqli_new->query("INSERT INTO world (username, userid, points, price, br, admin)
VALUES ('$word[username]',$word[userid], $points, 0, 0, '$word[adminname]')", MYSQLI_USE_RESULT);
$uresult = $mysqli_new->query("SELECT username FROM world WHERE userid='$word[userid]'", MYSQLI_USE_RESULT);
if ($uresult)
{
while ($row = $uresult->fetch_assoc())
{
echo "uresult: ".$row['username'] . PHP_EOL;
}
}
$uresult->close();