「PHP開発」非バッファクエリ( Unbuffered queries)でデータベースを操作するサンプル

方法1 mysqli
<?php
$mysqli = new mysqli(“localhost", “cft_user", “cft_pwd", “prodb");
$ctnResult = $mysqli->query(“SELECT cityInfo FROM Address", MYSQLI_USE_RESULT);

if ($ctnResult) {
while ($row = $ctnResult->fetch_assoc()) {
echo $row['cityInfo’] . PHP_EOL;
}
}
$ctnResult->close();

方法2 pdo_mysql
<?php
$pdo = new PDO(“mysql:host=localhost;dbcityInfo=prodb", 'cft_user’, 'cft_pwd’);
$pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);

$ctnResult = $pdo->query(“SELECT cityInfo FROM Address");
if ($ctnResult) {
while ($row = $ctnResult->fetch(PDO::FETCH_ASSOC)) {
echo $row['cityInfo’] . PHP_EOL;
}
}

方法3 mysql
<?php
$conn = mysql_connect(“localhost", “cft_user", “cft_pwd");
$db = mysql_select_db(“prodb");

$ctnResult = mysql_unbuffered_query(“SELECT cityInfo FROM Address");
if ($ctnResult) {
while ($row = mysql_fetch_assoc($ctnResult)) {
echo $row['cityInfo’] . PHP_EOL;
}
}

PHP

Posted by arkgame