(PHP 4 >= 4.3.0, PHP 5)
pg_meta_data — 獲得表的元數(shù)據(jù)
說明
array pg_meta_data ( resource$connection
, string $table_name
)
pg_metadata() 以數(shù)組形式返回 table_name 表的定義。
Warning此函數(shù)是實驗性的。此函數(shù)的表象,包括名稱及其相關(guān)文檔都可能在未來的 PHP 發(fā)布版本中未通知就被修改。使用本函數(shù)風(fēng)險自擔(dān) 。
參數(shù)
connection
PostgreSQL database connection resource.
table_name
The name of the table.
返回值
以數(shù)組 array 形式返回表的定義,如果出錯則返回 FALSE
。
范例
Example #1 取得表的元數(shù)據(jù)
<?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) } }
參見
pg_convert() - 將關(guān)聯(lián)的數(shù)組值轉(zhuǎn)換為適合 SQL 語句的格式。