(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
pg_meta_data — 獲得表的元數(shù)據(jù)
$connection, string $table_name): array
以數(shù)組形式返回 table_name 表的定義。
此函數(shù)是實驗性的。此函數(shù)的表象,包括名稱及其相關文檔都可能在未來的 PHP 發(fā)布版本中未通知就被修改。使用本函數(shù)風險自擔。
connectionPostgreSQL database connection resource.
table_nameThe name of the table.
以數(shù)組 array 形式返回表的定義,如果出錯則返回 false。
示例 #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)
}
}