This article mainly introduces three kinds of PHP non-buffered query APIs. Non-buffered queries are suitable for large data query. How PHP performs non-buffered queries. Interested friends can refer to it
Everyone knows about PHP's buffered mode query. The example listed below is how to execute the non-buffered query API.
Non-buffered query method one: mysqli
##
<?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(); ?>
Non-buffered query method two: pdo_mysql
##<?php $pdo = new PDO("mysql:host=localhost;dbname=world", 'my_user', 'my_pass'); $pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false); $uresult = $pdo->query("SELECT Name FROM City"); if ($uresult) { while ($row = $uresult->fetch(PDO::FETCH_ASSOC)) { echo $row['Name'] . PHP_EOL; } } ?>
<?php $conn = mysql_connect("localhost", "my_user", "my_pass"); $db = mysql_select_db("world"); $uresult = mysql_unbuffered_query("SELECT Name FROM City"); if ($uresult) { while ($row = mysql_fetch_assoc($uresult)) { echo $row['Name'] . PHP_EOL; } } ?>
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
Detailed graphic and text explanation of PHP two-dimensional array deduplication algorithmphp Detailed explanation of the three methods of obtaining POST data
##Think
Remove the index in the URL.php
The above is the detailed content of Three ways to implement non-buffered query API in PHP. For more information, please follow other related articles on the PHP Chinese website!