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

pg_port

PHP function Edit on GitHub ✎

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

Return the port number associated with the connection

Description

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

pg_port() returns the port number that the given PostgreSQL connection instance is connected to.

Parameters

connection

Connection-with-nullable-default

Return Values

A string containing the port number of the database server the connection is to, or empty string on error.

Changelog

VersionDescription
8.0.0connection is now nullable.

Examples

pg_port() example

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

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

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