pg_version

(PHP 5, PHP 7, PHP 8)

pg_version クライアント・プロトコル・サーバーのバージョンを配列で返す

説明

pg_version(resource $connection = ?): array

pg_version() はクライアント・プロトコル およびサーバーのバージョンを配列で返します。プロトコルおよびサーバーの バージョンは、PHP が PostgreSQL 7.4 以降とともにコンパイルされている 場合のみ有効です。

詳細なサーバー情報を取得するには pg_parameter_status() を参照ください。

パラメータ

connection

PostgreSQL データベース接続リソース。connection が指定されていない場合はデフォルトの接続が使用されます。 デフォルトの接続は、直近の pg_connect() あるいは pg_pconnect() によって作成されたものです。

返り値

client, protocol および server のキーとその値を持つ配列を 返します(有効な場合)。エラー時や接続が正常でない場合に false を返します。

例1 pg_version() の例

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

上の例の出力は以下となります。

7.4

参考

add a note add a note

User Contributed Notes 2 notes

up
0
mgchristensen
4 years ago
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"
up
0
live627
4 years ago
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) ""
}
To Top