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

pg_dbname

PHP function Edit on GitHub ✎

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

Get the database name

Description

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

pg_dbname() returns the name of the database that the given PostgreSQL connection instance.

Parameters

connection

Connection-with-nullable-default

Return Values

A string containing the name of the database the connection is to.

Changelog

VersionDescription
8.0.0connection is now nullable.

Examples

pg_dbname() example

php
<?php
  error_reporting(E_ALL);

  pg_connect("host=localhost port=5432 dbname=mary");
  echo pg_dbname(); // mary
?>

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