Home > Backend Development > PHP Tutorial > Three ways to implement non-buffered query API in PHP

Three ways to implement non-buffered query API in PHP

墨辰丷
Release: 2023-03-29 09:42:02
Original
1859 people have browsed it

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[&#39;Name&#39;] . PHP_EOL;
  }
}
$uresult->close();
?>
Copy after login

Non-buffered query method two: pdo_mysql

##
<?php
$pdo = new PDO("mysql:host=localhost;dbname=world", &#39;my_user&#39;, &#39;my_pass&#39;);
$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[&#39;Name&#39;] . PHP_EOL;
  }
}
?>
Copy after login

Non-buffered query Method three: mysql

<?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[&#39;Name&#39;] . PHP_EOL;
  }
}
?>
Copy after login

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 algorithm


php Detailed explanation of the three methods of obtaining POST data
##Think

php

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template