Pg_host - Manual - PHP

update page now
  • Downloads
  • Documentation
  • Get Involved
  • Help
  • PHP 8.5
Search docs Getting Started Introduction A simple tutorial Language Reference Basic syntax Types Variables Constants Expressions Operators Control Structures Functions Classes and Objects Namespaces Enumerations Errors Exceptions Fibers Generators Attributes References Explained Predefined Variables Predefined Exceptions Predefined Interfaces and Classes Predefined Attributes Context options and parameters Supported Protocols and Wrappers Security Introduction General considerations Installed as CGI binary Installed as an Apache module Session Security Filesystem Security Database Security Error Reporting User Submitted Data Hiding PHP Keeping Current Features HTTP authentication with PHP Cookies Sessions Handling file uploads Using remote files Connection handling Persistent Database Connections Command line usage Garbage Collection DTrace Dynamic Tracing Function Reference Affecting PHP's Behaviour Audio Formats Manipulation Authentication Services Command Line Specific Extensions Compression and Archive Extensions Cryptography Extensions Database Extensions Date and Time Related Extensions File System Related Extensions Human Language and Character Encoding Support Image Processing and Generation Mail Related Extensions Mathematical Extensions Non-Text MIME Output Process Control Extensions Other Basic Extensions Other Services Search Engine Extensions Server Specific Extensions Session Extensions Text Processing Variable and Type Related Extensions Web Services Windows Only Extensions XML Manipulation GUI Extensions Keyboard Shortcuts? This help j Next menu item k Previous menu item g p Previous man page g n Next man page G Scroll to bottom g g Scroll to top g h Goto homepage g s Goto search(current page) / Focus search box pg_insert » « pg_get_result
  • PHP Manual
  • Function Reference
  • Database Extensions
  • Vendor Specific Database Extensions
  • PostgreSQL
  • PostgreSQL Functions
Change language: English German Spanish French Italian Japanese Brazilian Portuguese Russian Turkish Ukrainian Chinese (Simplified) Other pg_host

(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): string

pg_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 note

User Contributed Notes 1 note

up down 0 mark at redbrick dot dcu dot ie22 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 note
  • PostgreSQL Functions
    • pg_​affected_​rows
    • pg_​cancel_​query
    • pg_​client_​encoding
    • pg_​close
    • pg_​connect
    • pg_​connect_​poll
    • pg_​connection_​busy
    • pg_​connection_​reset
    • pg_​connection_​status
    • pg_​consume_​input
    • pg_​convert
    • pg_​copy_​from
    • pg_​copy_​to
    • pg_​dbname
    • pg_​delete
    • pg_​end_​copy
    • pg_​escape_​bytea
    • pg_​escape_​identifier
    • pg_​escape_​literal
    • pg_​escape_​string
    • pg_​execute
    • pg_​fetch_​all
    • pg_​fetch_​all_​columns
    • pg_​fetch_​array
    • pg_​fetch_​assoc
    • pg_​fetch_​object
    • pg_​fetch_​result
    • pg_​fetch_​row
    • pg_​field_​is_​null
    • pg_​field_​name
    • pg_​field_​num
    • pg_​field_​prtlen
    • pg_​field_​size
    • pg_​field_​table
    • pg_​field_​type
    • pg_​field_​type_​oid
    • pg_​flush
    • pg_​free_​result
    • pg_​get_​notify
    • pg_​get_​pid
    • pg_​get_​result
    • pg_​host
    • pg_​insert
    • pg_​last_​error
    • pg_​last_​notice
    • pg_​last_​oid
    • pg_​lo_​close
    • pg_​lo_​create
    • pg_​lo_​export
    • pg_​lo_​import
    • pg_​lo_​open
    • pg_​lo_​read
    • pg_​lo_​read_​all
    • pg_​lo_​seek
    • pg_​lo_​tell
    • pg_​lo_​truncate
    • pg_​lo_​unlink
    • pg_​lo_​write
    • pg_​meta_​data
    • pg_​num_​fields
    • pg_​num_​rows
    • pg_​options
    • pg_​parameter_​status
    • pg_​pconnect
    • pg_​ping
    • pg_​port
    • pg_​prepare
    • pg_​put_​line
    • pg_​query
    • pg_​query_​params
    • pg_​result_​error
    • pg_​result_​error_​field
    • pg_​result_​memory_​size
    • pg_​result_​seek
    • pg_​result_​status
    • pg_​select
    • pg_​send_​execute
    • pg_​send_​prepare
    • pg_​send_​query
    • pg_​send_​query_​params
    • pg_​set_​chunked_​rows_​size
    • pg_​set_​client_​encoding
    • pg_​set_​error_​context_​visibility
    • pg_​set_​error_​verbosity
    • pg_​socket
    • pg_​trace
    • pg_​transaction_​status
    • pg_​tty
    • pg_​unescape_​bytea
    • pg_​untrace
    • pg_​update
    • pg_​version
To Top ↑ and ↓ to navigate • Enter to select • Esc to close • / to open Press Enter without selection to search using Google

Tag » How To Get Postgres Hostname