« oci_new_descriptor
oci_num_rows »

oci_num_fields

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

oci_num_fields — ある文における結果のカラム数を返す

説明

function oci_num_fields(resource $statement): int

指定した文 statement におけるカラムの数を返します。

パラメータ

statement

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

戻り値

カラムの数を表す整数値、あるいはエラー時に false を返します。

例

例1 oci_num_fields() の例

<?php

// 以下のテーブルを用意します
//   CREATE TABLE mytab (id NUMBER, quantity NUMBER);

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

$stid = oci_parse($conn, "SELECT * FROM mytab");
oci_execute($stid, OCI_DESCRIBE_ONLY); // 行をフェッチしない場合は OCI_DESCRIBE_ONLY を使います

$ncols = oci_num_fields($stid);
for ($i = 1; $i <= $ncols; $i++) {
    echo oci_field_name($stid, $i) . " " . oci_field_type($stid, $i) . "<br>\n";
}

// 出力は
//    ID NUMBER
//    QUANTITY NUMBER

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

?>

関連キーワード:
stid   カラム   fields   statement   conn   mytab   ncols   descriptor   rows   resource   ステートメント   整数   テーブル   用意   quantity   connect   hrpwd   localhost   trigger   htmlentities   message   parse   execute   フェッチ   type
関連する関数・ページ:
function.oci-field-is-null   function.oci-field-name   function.oci-field-type   function.oci-num-rows   function.oci-fetch-object   function.oci-field-scale