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

pg_client_encoding

PHP function Edit on GitHub ✎

(PHP 4 >= 4.0.3, PHP 5, PHP 7, PHP 8)

Gets the client encoding

Description

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

PostgreSQL supports automatic character set conversion between server and client for certain character sets. pg_client_encoding() returns the client encoding as a string. The returned string will be one of the standard PostgreSQL encoding identifiers.

Note

If libpq is compiled without multibyte encoding support, pg_client_encoding() always returns SQL_ASCII. Supported encoding depends on PostgreSQL version. Refer to the PostgreSQL Documentation supported encodings.

The function used to be called pg_clientencoding().

Parameters

connection

Connection-with-nullable-default

Return Values

The client encoding.

Changelog

VersionDescription
8.0.0connection is now nullable.

Examples

pg_client_encoding() example

php
<?php
// Assume $conn is a connection to a ISO-8859-1 database
$encoding = pg_client_encoding($conn);

echo "Client encoding is: ", $encoding, "\n";
?>

The above example will output:

output
Client encoding is: ISO-8859-1

See Also

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