pg_field_type_oid

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

pg_field_type_oid Devuelve el ID de tipo (OID) para el número de campo correspondiente

Descripción

pg_field_type_oid(PgSql\Result $result, int $field): string|int

pg_field_type_oid() devuelve un entero que contiene el OID del tipo base del campo field dado en la instancia result.

Puede obtenerse más información acerca del tipo de campo consultando la tabla del sistema de PostgreSQL pg_type() con el OID obtenido por esta función.

Nota:

Si el campo utiliza un dominio PostgreSQL (en lugar de un tipo básico), es el OID del dominio subyacente el que se devuelve, en lugar del OID del dominio como tal.

Parámetros

result

An PgSql\Result instance, returned by pg_query(), pg_query_params() or pg_execute()(among others).

field

Número del campo, comenzando en 0.

Valores devueltos

El OID del tipo base del campo.

Historial de cambios

Versión Descripción
8.1.0 The result parameter expects an PgSql\Result instance now; previously, a recurso was expected.

Ejemplos

Ejemplo #1 Recuperación de información de los campos

<?php
$dbconn
= pg_connect("dbname=publisher") or die("Conexión imposible");

// Se asume que 'título' es un tipo varchar
$res = pg_query($dbconn, "select título from autores where autor = 'Orwell'");

echo
"Tipo del campo título OID: ", pg_field_type_oid($res, 0);
?>

El resultado del ejemplo sería:

Tipo del campo título OID: 1043

Ver también

add a note

User Contributed Notes 2 notes

up
0
stanislav dot perfilov at gmail dot com
4 years ago
<?php

private function mapping($q, $result)
{
$types = [];
for (
$i = 0, $count = \pg_num_fields($q); $i < $count; ++$i) {
$types[$i] = \pg_field_type_oid($q, $i);
}
foreach (
$result as $k => &$row) {
$i = -1;
foreach (
$row as $name => &$value) {
++
$i;
if (
$value === null) {
continue;
}
switch (
$types[$i]) {
case
20:
case
21:
case
23: $value = (int)$value; break;
case
16507: /*$value = (string)$value; */break;
default:
throw new
\RuntimeException(
\pg_field_type($q, $i) .' type. Need mapping ' . \pg_field_type_oid($q, $i)
);
}
}
}
unset(
$value, $row);

return
$result;
}

?>
up
0
mauroi at digbang dot com
20 years ago
This function can be used to improve the performance of your application.
pg_field_type() makes an internal query to the pg_type table and it can be really slow.
So if your application previously know the oids of your database, you can save the execution time of this query in every request.
To Top