PHP Conference Ehime 2026

pg_service

(PHP 8 >= 8.5.0)

pg_serviceGets the service name of the connection

Description

function pg_service(?PgSql\Connection $connection = null): string

Returns the name of the connection service used to establish the connection, as defined in the connection service file.

This function is only available if PHP has been built against libpq 18 or later.

Parameters

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().

Warning

As of PHP 8.1.0, using the default connection is deprecated.

Return Values

A string containing the service name of the connection, or an empty string if no service was used.

See Also

  • pg_connect() - Open a PostgreSQL connection
  • pg_dbname() - Get the database name
  • pg_host() - Returns the host name associated with the connection
  • pg_port() - Return the port number associated with the connection
add a note

User Contributed Notes

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