pg_version

(PHP 5, PHP 7, PHP 8)

pg_version Returns an array with client, protocol and server version (when available)

说明

pg_version ( PgSql\Connection|null $connection = null ) : array

pg_version() returns an array with the client, protocol and server version. Protocol and server versions are only available if PHP was compiled with PostgreSQL 7.4 or later.

For more detailed server information, use pg_parameter_status().

参数

connection

An PgSql\Connection instance. When connection is null, the default connection is used. The default connection is the last connection made by pg_connect() or pg_pconnect().

返回值

Returns an array with client, protocol and server keys and values (if available).

更新日志

版本 说明
8.1.0 The connection parameter expects an PgSql\Connection instance now; previously, a 资源(resource) was expected.
8.0.0 connection is now nullable.

范例

Example #1 pg_version() example

<?php
  $dbconn 
pg_connect("host=localhost port=5432 dbname=mary")
     or die(
"Could not connect");
     
  
$v pg_version($dbconn);
  
  echo 
$v['client'];
?>

以上例程会输出:

7.4

参见

User Contributed Notes

mgchristensen 03-May-2020 03:19
I note that the array element for "protocol" seemingly has no value, being reported as:

 ["protocol"]=> int(3)

whereas the array element for e.g. "server" is reported as (in my particular case):

["server"]=> string(5) "10.12"

A call to json_encode() however gives:

"protocol":3 and "server":"10.12"
live627 07-Feb-2020 12:36
Complete output off this function for me is:

array(13) {
  ["client"]=>
  string(5) "9.6.9"
  ["protocol"]=>
  int(3)
  ["server"]=>
  string(4) "12.1"
  ["server_encoding"]=>
  string(4) "UTF8"
  ["client_encoding"]=>
  string(4) "UTF8"
  ["is_superuser"]=>
  string(2) "on"
  ["session_authorization"]=>
  string(8) "postgres"
  ["DateStyle"]=>
  string(8) "ISO, MDY"
  ["IntervalStyle"]=>
  string(8) "postgres"
  ["TimeZone"]=>
  string(10) "US/Arizona"
  ["integer_datetimes"]=>
  string(2) "on"
  ["standard_conforming_strings"]=>
  string(2) "on"
  ["application_name"]=>
  string(0) ""
}
PHP8中文手册 站长在线 整理 版权归PHP文档组所有