略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: oci_num_fields

2024-04-27

oci_num_fields

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

oci_num_fields返回结果列的数目

说明

oci_num_fields(resource $statement): int

oci_num_fields() 返回 statement 中的列的数目。

示例 #1 oci_num_fields() 例子

<?php
    
echo "<pre>\n";
    
$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);

    echo 
"</pre>";
?>

oci_num_fields() 在出错时返回 false

注意:

在 PHP 5.0.0 之前的版本必须使用 ocinumcols() 替代本函数。该函数名仍然可用,为向下兼容作为 oci_num_fields() 的别名。不过其已被废弃,不推荐使用。

add a noteadd a note

User Contributed Notes 1 note

up
0
jnield at impole dot com
22 years ago
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.

官方地址:https://www.php.net/manual/en/function.oci-num-fields.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3