pg_field_type

(PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8)

pg_field_type Retorna o nome do tipo para o número do campo correspondente

Descrição

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

pg_field_type() retorna uma string contendo o nome do tipo base do field na instância de result fornecida.

Nota:

Se o campo usar um domínio PostgreSQL (em vez de um tipo básico), será retornado o nome do tipo subjacente do domínio, e não o nome do próprio domínio.

Nota:

Esta função costumava ser chamada de pg_fieldtype().

Parâmetros

result

Uma instância de PgSql\Result, retornada por pg_query(), pg_query_params() ou pg_execute() (entre outras).

field

Número do campo, começando em 0.

Valor Retornado

Uma string contendo o nome base do tipo do campo.

Registro de Alterações

Versão Descrição
8.1.0 O parâmetro result agora espera uma instância de PgSql\Result; anteriormente, um resource era esperado.

Exemplos

Exemplo #1 Obtendo informações sobre campos

<?php
$dbconn
= pg_connect("dbname=publisher") or die("Não foi possível conectar");

// Suponha que 'título' seja um tipo varchar
$res = pg_query($dbconn, "select title from authors where author = 'Orwell'");

echo
"Tipo de campo: ", pg_field_type($res, 0);
?>

O exemplo acima produzirá:

Tipo de campo: varchar

Veja Também

adicione uma nota

Notas Enviadas por Usuários (em inglês) 4 notes

up
2
Joshua Burns
12 years ago
Here is an updated list of nearly every PostgreSQL data type, and PHP's internal C-type equivalent, updated for PostgreSQL 9.2. The first array maps PHP's internal data type to PostgreSQL's equivalents. The second maps PostgreSQL's data-types to PHP's equivalents.<?php$php_to_pg = array(    'bit' => array('bit'),    'bool' => array('boolean'),    'box' => array('box'),    'bpchar' => array('character','char'),    'bytea' => array('bytea'),    'cidr' => array('cidr'),    'circle' => array('circle'),    'date' => array('date'),    'daterange' => array('daterange'),    'float4' => array('real'),    'float8' => array('double precision'),    'inet' => array('inet'),    'int2' => array('smallint', 'smallserial'),    'int4' => array('integer', 'serial'),    'int4range' => array('int4range'),    'int8' => array('bigint', 'bigserial'),    'int8range' => array('int8range'),    'interval' => array('interval'),    'json' => array('json'),    'lseg' => array('lseg'),    'macaddr' => array('macaddr'),    'money' => array('money'),    'numeric' => array('decimal', 'numeric'),    'numrange' => array('numrange'),    'path' => array('path'),    'point' => array('point'),    'polygon' => array('polygon'),    'text' => array('text'),    'time' => array('time', 'time without time zone'),    'timestamp' => array('timestamp', 'timestamp without time zone'),    'timestamptz' => array('timestamp with time zone'),    'timetz' => array('time with time zone'),    'tsquery' => array('tsquery'),    'tsrange' => array('tsrange'),    'tsvector' => array('tsvector'),    'uuid' => array('uuid'),    'varbit' => array('bit varying'),    'varchar' => array('character varying', 'varchar'),    'xml' => array('xml'),);$pg_to_php = array(    'bit' => 'bit',    'boolean' => 'bool',    'box' => 'box',    'character' => 'bpchar',    'char' => 'bpchar',    'bytea' => 'bytea',    'cidr' => 'cidr',    'circle' => 'circle',    'date' => 'date',    'daterange' => 'daterange',    'real' => 'float4',    'double precision' => 'float8',    'inet' => 'inet',    'smallint' => 'int2',    'smallserial' => 'int2',    'integer' => 'int4',    'serial' => 'int4',    'int4range' => 'int4range',    'bigint' => 'int8',    'bigserial' => 'int8',    'int8range' => 'int8range',    'interval' => 'interval',    'json' => 'json',    'lseg' => 'lseg',    'macaddr' => 'macaddr',    'money' => 'money',    'decimal' => 'numeric',    'numeric' => 'numeric',    'numrange' => 'numrange',    'path' => 'path',    'point' => 'point',    'polygon' => 'polygon',    'text' => 'text',    'time' => 'time',    'time without time zone' => 'time',    'timestamp' => 'timestamp',    'timestamp without time zone' => 'timestamp',    'timestamp with time zone' => 'timestamptz',    'time with time zone' => 'timetz',    'tsquery' => 'tsquery',    'tsrange' => 'tsrange',    'tstzrange' => 'tstzrange',    'tsvector' => 'tsvector',    'uuid' => 'uuid',    'bit varying' => 'varbit',    'character varying' => 'varchar',    'varchar' => 'varchar',    'xml' => 'xml');?>
up
0
Anonymous
15 years ago
Also be aware that postgreSQL array fields will prefix the type name with an underscore (e.g. "_int4" or "_text"), while composite a.k.a. row-type fields will return type "record".
up
-1
andy at a 2 h d dot com
22 years ago
The types returned are:  bool  int2 (smallint)  int4  int8 (bigint)  numeric  float4 (real / float)  float8 (double)  timestamp  date  time  varchar  bpchar (fixed leng string, 'blank padded char')  inet (ip address)  moneyThere are some other more esoteric types, e.g. 'circle', but these are the most common.
up
-2
marxarelli
19 years ago
Because complete documentation is always helpful, here are all the PostgreSQL general purpose types as they are listed in the 8.1 documentation, and each corresponding string returned by pg_field_type().bigint => int8bigserial => int8bit => bitbit varying => varbitboolean => boolbox => boxbytea => byteacharacter varying => varcharcharacter => bpcharcidr => cidrcircle => circledate => datedouble precision => float8inet => inetinteger => int4interval => intervalline => linelseg => lsegmacaddr => macaddrmoney => moneynumeric => numericpath => pathpoint => pointpolygon => polygonreal => float4smallint => int2serial => int4text => texttime => timetime with time zone => timetztimestamp => timestamptimestamp with time zone => timestamptzAnd for the record... (note the 7.4 client lib)# postmaster --versionpostmaster (PostgreSQL) 8.0.4# ldd libphp4.so...libpq.so.3 => /usr/lib/libpq.so.3 (0xb7ac8000)...
To Top