array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'ja', ), 'this' => array ( 0 => 'function.pg-meta-data.php', 1 => 'pg_meta_data', ), 'up' => array ( 0 => 'ref.pgsql.php', 1 => 'PostgreSQL 関数', ), 'prev' => array ( 0 => 'function.pg-lo-write.php', 1 => 'pg_lo_write', ), 'next' => array ( 0 => 'function.pg-num-fields.php', 1 => 'pg_num_fields', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'ja', 'path' => 'reference/pgsql/functions/pg-meta-data.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
pg_meta_data — テーブルからメタデータを取得する
pg_meta_data() は、table_name
のテーブル定義を配列として返します。
connection
PgSql\Connection クラスのインスタンス。
table_name
テーブルの名前。
extended
拡張メタデータを返すかどうかを表すフラグ。デフォルトは false
。
テーブル定義の配列を返します。
失敗した場合に false
を返します
バージョン | 説明 |
---|---|
8.1.0 |
connection は、PgSql\Connection クラスのインスタンスを期待するようになりました。
これより前のバージョンでは、リソース を期待していました。
|
例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) } }