oci_num_fields

(PHP 5, PHP 7, PECL OCI8 >= 1.1.0)
Returns the number of result columns in a statement
int oci_num_fields ( resource $statement )

Gets the number of columns in the given statement.

Parameters:
statement

A valid OCI statement identifier.

Returns:

Returns the number of columns as an integer, or FALSE on errors.

Notes:

In PHP versions before 5.0.0 you must use ocinumcols() instead. This name still can be used, it was left as alias of oci_num_fields() for downwards compatability. This, however, is deprecated and not recommended.

Examples:
oci_num_fields() example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?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);
 
?>
doc_php
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.