Pg_host - Manual - PHP
Maybe your like
- Downloads
- Documentation
- Get Involved
- Help
-
- PHP Manual
- Function Reference
- Database Extensions
- Vendor Specific Database Extensions
- PostgreSQL
- PostgreSQL Functions
(PHP 4, PHP 5, PHP 7, PHP 8)
pg_host — Returns the host name associated with the connection
Description
pg_host(?PgSql\Connection $connection = null): stringpg_host() returns the host name of the given PostgreSQL connection instance is connected to.
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 name of the host the connection is to, or an empty string on error.
Changelog
| Version | Description |
|---|---|
| 8.1.0 | The connection parameter expects an PgSql\Connection instance now; previously, a resource was expected. |
| 8.0.0 | connection is now nullable. |
Examples
Example #1 pg_host() example
<?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
- pg_connect() - Open a PostgreSQL connection
- pg_pconnect() - Open a persistent PostgreSQL connection
Found A Problem?
Learn How To Improve This Page • Submit a Pull Request • Report a Bug +add a noteUser Contributed Notes 1 note
up down 0 mark at redbrick dot dcu dot ie ¶22 years ago This is a simple example of this function, which returns the name of which PostreSQL Database you are currently connected to. <?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; } ?> This function is extremely useful for sites which connect to multiple Postgresql services. Regards, --mark +add a noteTag » How To Get Postgres Hostname
-
Find The Host Name And Port Using PSQL Commands - Stack Overflow
-
How To Get Hostname In Postgresql? - DBA Stack Exchange
-
Get The Hostname Of Your PostgreSQL Deployment - ScaleGrid Docs
-
PostgreSQL — Faculty Platform Documentation
-
Hostname: Get The Server Host Name / PostgreSQL Extension Network
-
Documentation: 8.1: Connecting To The Database Server - PostgreSQL
-
Documentation: 8.4: System Information Functions - PostgreSQL
-
How Do I Find The Hostname In PostgreSQL? - MullOverThing
-
How To Set Up PostgreSQL Host For Remote Access
-
Quickstart: Create Server - Azure Database For PostgreSQL
-
Azure Database For PostgreSQL - Flexible Server | Microsoft Learn
-
5 Ways To Host PostgreSQL Databases
-
Connecting To PostgreSQL Database - Dataedo Documentation
-
How To Use A PostgreSQL Database With Your Web Hosting