PostgreSQL 函数
PHP 手册

pg_meta_data

(PHP 4 >= 4.3.0, PHP 5)

pg_meta_data 获得表的元数据

说明

array pg_meta_data ( resource $connection , string $table_name )

pg_metadata() 以数组形式返回 table_name 表的定义。如果出错则返回 FALSE

Example #1 取得表的元数据

<?php
    $dbconn 
pg_connect("dbname=publisher") or die("Could not connect");
    
$meta pg_meta_data($dbconn,'authors');
    if (
is_array ($meta)) {
        echo 
'<pre>';
        
var_dump ($meta);
        echo 
'</pre>';
    }
?>

上例输出如下:

array(3) {
  ["author"]=>
  array(5) {
    ["num"]=>
    int(1)
    ["type"]=>
    string(7) "varchar"
    ["len"]=>
    int(-1)
    ["not null"]=>
    bool(false)
    ["has default"]=>
    bool(false)
  }
  ["year"]=>
  array(5) {
    ["num"]=>
    int(2)
    ["type"]=>
    string(4) "int2"
    ["len"]=>
    int(2)
    ["not null"]=>
    bool(false)
    ["has default"]=>
    bool(false)
  }
  ["title"]=>
  array(5) {
    ["num"]=>
    int(3)
    ["type"]=>
    string(7) "varchar"
    ["len"]=>
    int(-1)
    ["not null"]=>
    bool(false)
    ["has default"]=>
    bool(false)
  }
}

Warning

本函数是实验性的。本函数的行为,包括函数名称以及其它任何关于本函数的文档可能会在没有通知的情况下随 PHP 以后的发布而改变。使用本函数风险自担。

参见 pg_convert()


PostgreSQL 函数
PHP 手册