Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: oci_fetch_array - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

oci_fetch_assoc" width="11" height="7"/> <oci_fetch_all
Last updated: Thu, 31 May 2007

view this page in

oci_fetch_array

(PHP 5, PECL oci8:1.1-1.2.3)

oci_fetch_array — 結果データからの次の行を連想配列または配列、またはその両方で返す

説明

array oci_fetch_array ( resource $statement [, int $mode] )

次の結果行に相当する配列を返します。

oci8 ドライバによるデータ型マッピングの 詳細については、ドライバが サポートするデータ型 を参照ください。

ここで言っておくべき事は、oci_fetch_array()oci_fetch_row() よりも 無意味に 遅い、ということですが、非常に使いやすい関数です。

パラメータ

statement

有効な OCI ステートメント ID。

statement

オプションの第2引数は、次の定数の組み合わせが可能です。

OCI_BOTH - 連想配列と配列の両方を返します (OCI_ASSOC + OCI_NUM と同等)。 これはデフォルトの動作です。
OCI_ASSOC - 連想配列を返します (oci_fetch_assoc() と同等)。
OCI_NUM - 配列を返します (oci_fetch_row() と同等)。
OCI_RETURN_NULLS - フィールドが NULL の場合、 空の要素を返します。
OCI_RETURN_LOBS - ディスクリプタの LOB の値を返します。

デフォルトの modeOCI_BOTH です。

返り値

連想配列あるいは配列の両方を返します。 失敗時あるいは結果行がない場合は FALSE を返します。

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

注意: Oracle は全てのフィールド名を大文字で返し、 結果の連想配列のインデックスも大文字になります。

例 1594. OCI_BOTH を使った oci_fetch_array() の例

<?php
$connection
= oci_connect("apelsin", "kanistra");

$query = "SELECT id, name FROM fruits";

$statement = oci_parse ($connection, $query);
oci_execute ($statement);

while (
$row = oci_fetch_array ($statement, OCI_BOTH)) {
    echo
$row[0]." and ".$row['ID']." is the same<br>";
    echo
$row[1]." and ".$row['NAME']." is the same<br>";
}
?>

例 1595. OCI_NUM を使った oci_fetch_array() の例

<?php
$connection
= oci_connect("user", "password");

$query = "SELECT id, name, lob_field FROM fruits";

$statement = oci_parse ($connection, $query);
oci_execute ($statement);

while (
$row = oci_fetch_array ($statement, OCI_NUM)) {
    echo
$row[0]."<br>";
    echo
$row[1]."<br>";
    echo
$row[2]->read(100)."<br>"//this will output first 100 bytes from LOB
}
?>

例 1596. OCI_ASSOC を使った oci_fetch_array() の例

<?php
$connection
= oci_connect("user", "password");

$query = "SELECT id, name, lob_field FROM fruits";

$statement = oci_parse ($connection, $query);
oci_execute ($statement);

while (
$row = oci_fetch_array ($statement, OCI_ASSOC)) {
    echo
$row['ID']."<br>";
    echo
$row['NAME']."<br>";
    echo
$row['LOB_FIELD']."<br>"//this will output "Object id #1"
}
?>

例 1597. OCI_RETURN_LOBS を使った oci_fetch_array() の例

<?php
$connection
= oci_connect("user", "password");

$query = "SELECT id, name, lob_field FROM fruits";

$statement = oci_parse ($connection, $query);
oci_execute ($statement);

while (
$row = oci_fetch_array ($statement, (OCI_NUM+OCI_RETURN_LOBS))) {
    echo
$row[0]."<br>";
    echo
$row[1]."<br>";
    echo
$row['LOB_FIELD']."<br>"//this will output LOB's content
}
?>

参考

oci_fetch_assoc()
oci_fetch_object()
oci_fetch_row()
oci_fetch_all()



add a note add a note User Contributed Notes
oci_fetch_array
badr at arabiadata dot com
18-Jul-2006 09:14
generating dynamic drop down list
<SELECT name="reason" id="vacation_code">
<OPTION value=0 selected>Choose </OPTION>
<?php
$query2
= "SELECT IN_NAME, IN_CODE FROM HR_IN_REASON ";
$statement2 = oci_parse ($conn, $query2);
oci_execute ($statement2);
while (
$row = oci_fetch_array ($statement2, OCI_NUM)) {
 
?>
                  <option value="<?  echo $row[1]; ?>"> <? echo $row[0] ?> </option>
                  <? }
?>
                </select>
antonchanning at gmail dot com
18-Apr-2006 05:59
As Robert Hicks mentioned back in August 2004 there is an error in examples 3 and 4 of this page.  The error in example 3 is what dwhitaker and stry_cat address in their notes of 20 May 2005 and 9 June 2005 respectively.

The correct form of example 4 should read:

<?php
$connection
= oci_connect("user", "password");

$query = "SELECT id, name, lob_field FROM fruits";

$statement = oci_parse ($connection, $query);
oci_execute ($statement);

while (
$row = oci_fetch_array ($statement, OCI_RETURN_LOBS)) {
   echo
$row[0]."<br>";
   echo
$row[1]."<br>";
   echo
$row['LOB_FIELD']."<br>"//this will output LOB's content
}
?>

This really should be corrected in the actual documentation...
stry_cat at yahoo dot com
28-Jan-2006 01:29
If you want to get both nulls and an assoc array, you have to ADD the values like this:

$row = oci_fetch_array($stmt, OCI_RETURN_NULLS + OCI_ASSOC);

This really should be noted in the text of the manual.
10-Jun-2005 12:13
OCI_BOTH is the default.

If you just need to return all fields, you can leave out OCI_NUM & OCI_ASSOC.

EXAMPLE:

<?php
$connection
= ocilogon("user", "password", "dbname");

$query = "SELECT id, name, lob_field FROM fruits";

$statement = oci_parse ($connection, $query);
oci_execute ($statement);

while (
$row = oci_fetch_array ($statement)) {
  
$id = $row['ID'];
  
$name = $row['NAME'];
  
$lob_field = $row['LOB_FIELD'];

   echo
$id.' '.$name.' '.$lob_field;

}
?>
dwhitaker at dfwairport dot com
20-May-2005 11:39
Example 3 above is incorrect...

OCI_NUM should be OCI_ASSOC

So it should read something like this:

<?php
$connection
= ocilogon("user", "password", "dbname");

$query = "SELECT id, name, lob_field FROM fruits";

$statement = oci_parse ($connection, $query);
oci_execute ($statement);

while (
$row = oci_fetch_array ($statement, OCI_ASSOC)) {
  
$id = $row['ID'];
  
$name = $row['NAME'];
  
$lob_field = $row['LOB_FIELD'];

   echo
$id.' '.$name.' '.$lob_field;

}
?>
robert dot hicks at gmail dot com
10-Aug-2004 09:57
OCI_NUM should be changed in the various scripts to the appropriate call to the OCI_*. For example the script to show the OCI_ASSOC call still has OCI_NUMS in it.

oci_fetch_assoc" width="11" height="7"/> <oci_fetch_all
Last updated: Thu, 31 May 2007
 
 
show source | credits | sitemap | contact | advertising | mirror sites