Oci_fetch_all() will return data only the first time it is called after an oci_execute(). It cannot be used to "page" data.
oci_fetch_all
(PHP 5, PECL oci8 >= 1.1.0)
oci_fetch_all — 結果データの全ての行を配列に取得する
説明
int oci_fetch_all
( resource $statement
, array &$output
[, int $skip
[, int $maxrows
[, int $flags
]]] )
全ての行の結果をユーザー定義の配列に格納して取得します。
oci8 ドライバによるデータ型マッピングの 詳細については、ドライバが サポートするデータ型 を参照ください。
パラメータ
- statement
-
有効な OCI ステートメント ID。
- output
-
注意: この関数は、 NULL フィールドに PHPの NULL 値を設定します。
- skip
-
結果を取得する際に無視する行数 (デフォルトの値は 0 で、最初の行から開始されます) 。
- maxrows
-
読み込む行数。 skip 番目の行から開始されます (デフォルトは -1 で、全ての行 を意味します)。
- flags
-
パラメータ flags には次の値の組み合わせが可能です。
- OCI_FETCHSTATEMENT_BY_ROW
- OCI_FETCHSTATEMENT_BY_COLUMN (デフォルト値)
- OCI_NUM
- OCI_ASSOC
返り値
取得した行数、失敗した場合 FALSE を返します。
例
例1 oci_fetch_all() の例
<?php
/* oci_fetch_all の例 mbritton at verinet dot com (990624) */
$conn = oci_connect("scott", "tiger");
$stmt = oci_parse($conn, "select * from emp");
oci_execute($stmt);
$nrows = oci_fetch_all($stmt, $results);
if ($nrows > 0) {
echo "<table border=\"1\">\n";
echo "<tr>\n";
foreach ($results as $key => $val) {
echo "<th>$key</th>\n";
}
echo "</tr>\n";
for ($i = 0; $i < $nrows; $i++) {
echo "<tr>\n";
foreach ($results as $data) {
echo "<td>$data[$i]</td>\n";
}
echo "</tr>\n";
}
echo "</table>\n";
} else {
echo "No data found<br />\n";
}
echo "$nrows Records Selected<br />\n";
oci_free_statement($stmt);
oci_close($conn);
?>
注意
注意: PHP バージョン 5.0.0 以前では、代わりに ocifetchstatement() を使用しなければなりません。 まだこの名前を使用することができ、下位互換性のため oci_fetch_all() への別名として残されていますが、 推奨されません。
oci_fetch_all
sixd at php dot net
23-Jan-2009 02:45
23-Jan-2009 02:45
sixd at php dot net
20-Nov-2008 04:24
20-Nov-2008 04:24
Avoid using the "skip" and "maxrows" parameters. The function works by fetching and discarding all rows up to the "skip'th" row. This wastes network and CPU. It is better to rewrite the query and use ROWNUM (or similar) to limit the rows the DB returns.
dawid.krysiak.net.pl
11-Jul-2007 03:55
11-Jul-2007 03:55
It looks like passing 0 (zero) as a $maxrows parameter is treated identically as -1 value - all the rows are returned.
OCIfetchstatement($stmt, $res, 1, 0, OCI_FETCHSTATEMENT_BY_ROW)
Tested under: PHP 4.4.3, WinXP pro
stry_cat at yahoo dot com
07-Feb-2007 05:43
07-Feb-2007 05:43
If you want to use more than one flag, you need to use the + to connect them:
<?php
oci_fetch_all($stmt, $row, "0", "-1", OCI_ASSOC+OCI_FETCHSTATEMENT_BY_ROW);
?>
jnavratil at houston dot rr dot com
13-Feb-2006 12:46
13-Feb-2006 12:46
The number of rows returned is the number actually fetched, not the number potentially available. If one limits the number of rows to fetch, the number of rows returned will be bound by that limit. For example...
$nrows = oci_fetch_all($statement, $results, 0, 1);
would result in a returned value of '0' if there are no rows found for the statement, or '1' if any rows were found, regardless of the number actually present in the database.
