PHP Doku:: Gibt den Datentyp eines Feldes zurück - function.pg-field-type.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDatenbankerweiterungenAnbieterspezifische DatenbankerweiterungenPostgreSQLPostgreSQL-Funktionenpg_field_type

Ein Service von Reinhard Neidl - Webprogrammierung.

PostgreSQL-Funktionen

<<pg_field_type_oid

pg_free_result>>

pg_field_type

(PHP 4 >= 4.2.0, PHP 5)

pg_field_type Gibt den Datentyp eines Feldes zurück

Beschreibung

string pg_field_type ( resource $result , int $field_number )

pg_field_type() gibt den Basistyp des Feldes mit der Nummer field_number im PostgreSQL Abfrageergebnis result zurück.

Hinweis:

Wenn das Feld anstatt eines Basis-Datentyps einen Typ einer PostgreSQL Domain besitzt, wird der Name des Datentyps zurückgegeben, auf dem die Domain definiert ist und nicht der Name der Domain.

Hinweis:

Diese Funktion ersetzt die Funktion pg_fieldtype().

Parameter-Liste

result

PostgreSQL Verbindungskennung, die (unter anderenm) von den Funktionen pg_query(), pg_query_params() oder pg_execute() zurückgegeben wurde.

field_number

Die Feldnummer, beginnend bei 0.

Rückgabewerte

Ein string, der den Datentyp des Feldes enthält oder false;, falls ein Fehler auftrat.

Beispiele

Beispiel #1 Informationen über Felder holen

<?php
  $dbconn 
pg_connect("dbname=publisher") or die
            (
"Konnte keine Verbindung aufbauen");

  
// Angenommen 'title' hat den Typ varchar
  
$res pg_query($dbconn"select title from authors where author = 'Orwell'");

  echo 
"Der Datentyp von title ist: "pg_field_type($res0);
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

Der Datentyp von title ist: varchar

Siehe auch


3 BenutzerBeiträge:
- Beiträge aktualisieren...
Anonymous
17.01.2010 4:18
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".
marxarelli
2.01.2006 23:34
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 => int8
bigserial => int8
bit => bit
bit varying => varbit
boolean => bool
box => box
bytea => bytea
character varying => varchar
character => bpchar
cidr => cidr
circle => circle
date => date
double precision => float8
inet => inet
integer => int4
interval => interval
line => line
lseg => lseg
macaddr => macaddr
money => money
numeric => numeric
path => path
point => point
polygon => polygon
real => float4
smallint => int2
serial => int4
text => text
time => time
time with time zone => timetz
timestamp => timestamp
timestamp with time zone => timestamptz

And for the record... (note the 7.4 client lib)
# postmaster --version
postmaster (PostgreSQL) 8.0.4

# ldd libphp4.so
...
libpq.so.3 => /usr/lib/libpq.so.3 (0xb7ac8000)
...
andy at a 2 h d dot com
3.05.2003 21:09
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)
  money

There are some other more esoteric types, e.g. 'circle', but these are the most common.



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)