pg_meta_data

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

pg_meta_data 获得表的元数据

说明

pg_meta_data(PgSql\Connection $connection, string $table_name, bool $extended = false): array|false

pg_metadata() 以数组形式返回 table_name 的表定义。

参数

connection

PgSql\Connection 实例。

table_name

表名。

extended

用于返回扩展元数据的 flag。默认为 false

返回值

array 形式返回表定义, 或者在失败时返回 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)
}
}

参见

  • pg_convert() - 将关联的数组值转换为适合 SQL 语句的格式

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top