php8.5
Home/ Manual/ pgsql / functions/ pg_meta_data

pg_meta_data

PHP function Edit on GitHub ✎

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

Get meta data for table

Description

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

pg_meta_data() returns table definition for table_name as an array.

Parameters

connection

Connection

table_name

The name of the table.

extended

Flag for returning extended meta data. Default to false.

Return Values

An array of the table definition, Falseforfailure.

Changelog

VersionDescription

Examples

Getting table metadata

php
<?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>';
  }
?>

The above example will output:

output
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)
}
}

See Also

Source: reference/pgsql/functions/pg-meta-data.xml · from the official PHP manual (php/doc-en)