mysqli_result::data_seek
mysqli_data_seek
(PHP 5, PHP 7)
mysqli_result::data_seek -- mysqli_data_seek — 結果の任意の行にポインタを移動する
説明
オブジェクト指向型
public mysqli_result::data_seek
( int $offset
) : bool
手続き型
mysqli_data_seek
( mysqli_result $result
, int $offset
) : bool
mysqli_data_seek() 関数は、
結果セットの任意の行 offset
にポインタを移動します。
パラメータ
result
- 手続き型のみ: mysqli_query()、mysqli_store_result() あるいは mysqli_use_result() が返す結果セット ID。
offset
- フィールドオフセット。ゼロから全行数 - 1 までの間 (0..mysqli_num_rows() - 1)である必要があります。
返り値
成功した場合に true
を、失敗した場合に false
を返します。
注意
注意:
この関数は、mysqli_store_result() あるいは mysqli_query() によって取得した、 バッファに格納されている結果に対してのみ使用可能です。
例
例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 Name";if ($result = $mysqli->query($query)) { /* 行番号 400 に移動します */ $result->data_seek(399); /* 行を取得します */ $row = $result->fetch_row(); printf ("City: %s Countrycode: %s\n", $row[0], $row[1]); /* 結果セットを開放します */ $result->close();}/* 接続を閉じます */$mysqli->close();?>
例2 手続き型
<?php/* 接続を開きます */$link = mysqli_connect("localhost", "my_user", "my_password", "world");/* 接続状況をチェックします */ if (!$link) { printf("Connect failed: %s\n", mysqli_connect_error()); exit();}$query = "SELECT Name, CountryCode FROM City ORDER BY Name";if ($result = mysqli_query($link, $query)) { /* 行番号 400 に移動します */ mysqli_data_seek($result, 399); /* 行を取得します */ $row = mysqli_fetch_row($result); printf ("City: %s Countrycode: %s\n", $row[0], $row[1]); /* 結果セットを開放します */ mysqli_free_result($result);}/* 接続を閉じます */mysqli_close($link);?>
上の例の出力は以下となります。
City: Benin City Countrycode: NGA
参考
- mysqli_store_result() - 直近のクエリから結果セットを転送する
- mysqli_fetch_row() - 結果の行を数値添字配列で取得する
- mysqli_fetch_array() - 結果の行を連想配列・数値添字配列あるいはその両方の形式で取得する
- mysqli_fetch_assoc() - 結果の行を連想配列で取得する
- mysqli_fetch_object() - 結果セットの現在の行をオブジェクトとして返す
- mysqli_query() - データベース上でクエリを実行する
- mysqli_num_rows() - 結果の行数を取得する