PHP 8.4.6 Released!

oci_num_fields

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

oci_num_fieldsRetorna o número de colunas de resultados em uma instrução

Descrição

oci_num_fields(resource $statement): int

Obtém o número de colunas na instrução fornecida em statement.

Parâmetros

statement

Um identificador de instrução OCI válido.

Valor Retornado

Retorna o número de colunas como um int.

Exemplos

Exemplo #1 Exemplo de oci_num_fields()

<?php

// Crie a tabela com:
// 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 se não estiver buscando linhas

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

// Resultado:
// ID NUMBER
// QUANTITY NUMBER

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

?>

adicione uma nota

Notas Enviadas por Usuários (em inglês) 1 note

up
0
jnield at impole dot com
25 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.
To Top