php8.5
Home/ Manual/ oci8 / functions/ oci_num_fields

oci_num_fields

PHP function Edit on GitHub ✎

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

Returns the number of result columns in a statement

Description

oci_num_fields(resource $statement): int

Gets the number of columns in the given statement.

Parameters

statement

A valid OCI statement identifier.

Return Values

Returns the number of columns as an int.

Examples

oci_num_fields() example

php
<?php

// Create the table with:
//   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); // Use OCI_DESCRIBE_ONLY if not fetching rows

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

// Outputs:
//    ID NUMBER
//    QUANTITY NUMBER

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

?>

Source: reference/oci8/functions/oci-num-fields.xml · from the official PHP manual (php/doc-en)