PHP mysql_client_encoding() Function

Definition and Usage

The mysql_client_encoding() function returns the name of the character set of the current connection.

Syntax

mysql_client_encoding(link_identifier)
Parameters Description
link_identifier Required. MySQL connection identifier. If not specified, the last one connected to is used by default. mysql_connect() Open connection. If the connection is not found, the function will attempt to call mysql_connect() Establishes a connection and uses it. If an error occurs, no connection is found or cannot be established, the system issues a warning message at the E_WARNING level.

Description

Returns the value of the character_set variable from MySQL.

Return Value

Returns the name of the default character set of the current connection.

Examples

<?php
$con = mysql_connect("localhost","mysql_user","mysql_pwd");
if (!$con)
  {
  die("Could not connect: " . mysql_error());
  }
$charset = mysql_client_encoding($con);
echo "The current character set is: $charset";
mysql_close($con);
?>

Output:

The current character set is: latin1