pg_meta_data
(PHP 4 >= 4.3.0, PHP 5, PHP 7)
pg_meta_data — テーブルからメタデータを取得する
説明
pg_meta_data
( resource $connection
, string $table_name
[, bool $extended
= false
] ) : array
pg_meta_data() は、table_name
のテーブル定義を配列として返します。
パラメータ
connection
- PostgreSQL データベースの接続リソース。
table_name
- テーブルの名前。
extended
- 拡張メタデータを返すかどうかを表すフラグ。デフォルトは
false
。
返り値
テーブル定義の配列を返します。エラー時には 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) } }
変更履歴
バージョン | 説明 |
---|---|
5.6.0 | 実験的な関数ではなくなりました。デフォルト属性として "is enum" が追加されました。
|