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

pg_host

PHP function Edit on GitHub ✎

(PHP 4, PHP 5, PHP 7, PHP 8)

Returns the host name associated with the connection

Description

pg_host(PgSql\Connection|null $connection = null): string

pg_host() returns the host name of the given PostgreSQL connection instance is connected to.

Parameters

connection

Connection-with-nullable-default

Return Values

A string containing the name of the host the connection is to, or an empty string on error.

Changelog

VersionDescription
8.0.0connection is now nullable.

Examples

pg_host() example

php
<?php
$pgsql_conn = pg_connect("dbname=mark host=localhost");

if ($pgsql_conn) {
   print "Successfully connected to: " . pg_host($pgsql_conn) . "<br/>\n";
} else {
   print pg_last_error($pgsql_conn);
   exit;
}
?>

See Also

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