oci_fetch_all

(PHP 5)

oci_fetch_all -- 获取结果数据的所有行到一个数组

说明

int oci_fetch_all ( resource statement, array &output [, int skip [, int maxrows [, int flags]]] )

oci_fetch_all() 从一个结果中获取所有的行到一个用户定义的数组。oci_fetch_all() 返回获取的行数,出错则返回 FALSEskip 是从结果中获取数据时,最开始忽略的行数(默认值是 0,即从第一行开始)。maxrows 是要读取的行数,从第 skip 行开始(默认值是 -1,即所有行)。

注: 本函数对 PHP NULL 值设定 NULL 字段。

flags 参数可以是下列值的任意组合:

OCI_FETCHSTATEMENT_BY_ROW
OCI_FETCHSTATEMENT_BY_COLUMN(默认值)
OCI_NUM
OCI_ASSOC

例子 1. oci_fetch_all() 例子

<?php
/* oci_fetch_all example 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);
?>

有关 OCI8 驱动程序执行的数据类型映射的细节,见驱动程序支持的数据类型

oci_fetch_all() 如果出错则返回 FALSE

注: 在 PHP 5.0.0 之前的版本必须使用 ocifetchstatement() 替代本函数。该函数名仍然可用,为向下兼容作为 oci_fetch_all() 的别名。不过其已被废弃,不推荐使用。


add a note add a note User Contributed Notes
jnavratil at houston dot rr dot com
13-Feb-2006 06: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.