PHP 8.3.4 Released!

oci_fetch

(PHP 5, PHP 7, PHP 8, PECL OCI8 >= 1.1.0)

oci_fetchクエリの次の行を内部バッファに取得する

説明

oci_fetch(resource $statement): bool

クエリの次の行を内部バッファに取得します。このバッファへは oci_result() でアクセスできます。あるいは、 oci_define_by_name() で事前に定義した変数を使ってアクセスすることもできます。

データの取得に関する全般的な情報は oci_fetch_array() を参照ください。

パラメータ

statement

oci_parse() で作成して oci_execute() で実行した有効な OCI8 ステートメント ID、 あるいは REF CURSOR ステートメント ID。

戻り値

成功した場合に truestatement にもう行がない場合に false を返します。

例1 oci_fetch() での定義済みの変数の使用

<?php

$conn
= oci_connect('hr', 'welcome', 'localhost/XE');
if (!
$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$sql = 'SELECT location_id, city FROM locations WHERE location_id < 1200';
$stid = oci_parse($conn, $sql);

// 実行前に定義しておく必要があります
oci_define_by_name($stid, 'LOCATION_ID', $locid);
oci_define_by_name($stid, 'CITY', $city);

oci_execute($stid);

// フェッチするたびに、次の行のデータが定義済みの変数に格納されます
while (oci_fetch($stid)) {
echo
"Location id $locid is $city<br>\n";
}

// 表示:
// Location id 1000 is Roma
// Location id 1100 is Venice

oci_free_statement($stid);
oci_close($conn);

?>

例2 oci_fetch()oci_result() の使用例

<?php

$conn
= oci_connect('hr', 'welcome', 'localhost/XE');
if (!
$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}

$sql = 'SELECT location_id, city FROM locations WHERE location_id < 1200';
$stid = oci_parse($conn, $sql);
oci_execute($stid);

while (
oci_fetch($stid)) {
echo
oci_result($stid, 'LOCATION_ID') . " is ";
echo
oci_result($stid, 'CITY') . "<br>\n";
}

// 表示:
// 1000 is Roma
// 1100 is Venice

oci_free_statement($stid);
oci_close($conn);

?>

注意

注意:

Oracle Database の暗黙の結果セットからの行は返しません。 代わりに oci_fetch_array() を使いましょう。

参考

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top