The following is not immediately obvious:
If you need the number of columns in a REF CURSOR returned from a PL/SQL procedure, you need to use OCINumColumns() on the cursor handle returned by OCINewCursor after it is bound and executed, not the statement handle. Same applies for OCIColumnName() and friends.
oci_num_fields
(PHP 5, PECL OCI8 >= 1.1.0)
oci_num_fields — ある文における結果のカラム数を返す
説明
int oci_num_fields
( resource
$statement
)
指定した文 statement
におけるカラムの数を返します。
パラメータ
-
statement -
有効な OCI ステートメント ID。
返り値
カラムの数を表す整数値、あるいはエラー時に FALSE を返します。
例
例1 oci_num_fields() の例
<?php
$conn = oci_connect("scott", "tiger");
$stmt = oci_parse($conn, "select * from emp");
oci_execute($stmt);
while (oci_fetch($stmt)) {
echo "\n";
$ncols = oci_num_fields($stmt);
for ($i = 1; $i <= $ncols; $i++) {
$column_name = oci_field_name($stmt, $i);
$column_value = oci_result($stmt, $i);
echo $column_name . ': ' . $column_value . "\n";
}
echo "\n";
}
oci_free_statement($stmt);
oci_close($conn);
?>
注意
注意:
PHP バージョン 5.0.0 以前では、代わりに ocinumcols() を使用しなければなりません。 まだこの名前を使用することができ、下位互換性のため oci_num_fields() への別名として残されていますが、 推奨されません。
jnield at impole dot com
18-Nov-1999 07:43
