pg_meta_data
(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
pg_meta_data — 獲得表的後設資料
說明
pg_meta_data(resource
$connection, string $table_name): array
pg_metadata() 以陣列形式返回 table_name 表的定義。
警告
此函式是實驗性的。此函式的表象,包括名稱及其相關文件都可能在未來的 PHP 發佈版本中未通知就被修改。使用本函式風險自擔。
參數
-
connection -
PostgreSQL database connection resource.
-
table_name -
The name of the table.
返回值
以陣列 array 形式返回表的定義,如果出錯則返回 false。
範例
示例 #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)
}
}