导航首页 » 技术教程 » PHP:pg_meta_data()的用法_PostgreSQL函数
PHP:pg_meta_data()的用法_PostgreSQL函数 157 2023-12-12   

pg_meta_data

(PHP 4 >= 4.3.0, PHP 5)

pg_meta_data — 获得表的元数据

说明

array pg_meta_data ( resource $connection , string $table_name )

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

Warning

此函数是实验性的。此函数的表象,包括名称及其相关文档都可能在未来的 PHP 发布版本中未通知就被修改。使用本函数风险自担 。

参数

connection

PostgreSQL database connection resource.

table_name

The name of the table.

返回值

以数组 array 形式返回表的定义,如果出错则返回 FALSE

范例

Example #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 语句的格式。


!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103