The MySQLi_Result class
PHP Manual

mysqli_result::fetch_row

mysqli_fetch_row

(PHP 5)

mysqli_result::fetch_row -- mysqli_fetch_row結果の行を数値添字配列で取得する

説明

オブジェクト指向型(メソッド):

mixed mysqli_result::fetch_row ( void )

手続き型:

mixed mysqli_fetch_row ( mysqli_result $result )

結果セットからデータを 1 行取得し、それを数値添字の配列で 返します。各カラムは 0(ゼロ)から始まる添字に格納されます。 mysqli_fetch_row() 関数を続けてコールすると、 結果セットの次の行を返します。もしもう行がない場合には NULL を返します。

パラメータ

result

手続き型のみ: mysqli_query()mysqli_store_result() あるいは mysqli_use_result() が返す結果セット ID。

返り値

mysqli_fetch_row() は取得した行に対応する文字列の配列を 返します。もしもう行がない場合には NULL を返します。

注意: この関数は、 NULL フィールドに PHPの NULL 値を設定します。

例1 オブジェクト指向型

<?php
$mysqli 
= new mysqli("localhost""my_user""my_password""world");

/* 接続状況をチェックします */
if (mysqli_connect_errno()) {
    
printf("Connect failed: %s\n"mysqli_connect_error());
    exit();
}

$query "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";

if (
$result $mysqli->query($query)) {

    
/* 配列を取得します */
    
while ($row $result->fetch_row()) {
        
printf ("%s (%s)\n"$row[0], $row[1]);
    }

    
/* 結果セットを開放します */
    
$result->close();
}

/* 接続を閉じます */
$mysqli->close();
?>

例2 手続き型

<?php
$link 
mysqli_connect("localhost""my_user""my_password""world");

/* 接続状況をチェックします */
if (mysqli_connect_errno()) {
    
printf("Connect failed: %s\n"mysqli_connect_error());
    exit();
}

$query "SELECT Name, CountryCode FROM City ORDER by ID DESC LIMIT 50,5";

if (
$result mysqli_query($link$query)) {

    
/* 配列を取得します */
    
while ($row mysqli_fetch_row($result)) {
        
printf ("%s (%s)\n"$row[0], $row[1]);
    }

    
/* 結果セットを開放します */
    
mysqli_free_result($result);
}

/* 接続を閉じます */
mysqli_close($link);
?>

上の例の出力は以下となります。

Pueblo (USA)
Arvada (USA)
Cape Coral (USA)
Green Bay (USA)
Santa Clara (USA)

参考


The MySQLi_Result class
PHP Manual
アダルトレンタルサーバー