(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
pg_meta_data — テーブルからメタデータを取得する
pg_meta_data() は、table_name
のテーブル定義を配列として返します。
connectionPgSql\Connection クラスのインスタンス。
table_nameテーブルの名前。
extended
拡張メタデータを返すかどうかを表すフラグ。デフォルトは false。
テーブル定義の配列を返します。
失敗した場合に false を返します
| バージョン | 説明 |
|---|---|
| 8.1.0 |
connection は、PgSql\Connection クラスのインスタンスを期待するようになりました。
これより前のバージョンでは、resource を期待していました。
|
例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)
}
}