English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The mysqli_character_set_name() function returns the default character encoding of the current database connection
mysqli_character_set_name()The function returns the name of the default character set of the current database connection.
mysqli_character_set_name($con)
Serial number | Parameters and descriptions |
---|---|
1 | con(Required) This is an object representing the connection to the MySQL Server. |
mysqli_character_set_name()The function returns a string value representing the current character set.
This function was initially introduced in PHP version5introduced and can be used in all higher versions.
The following examples demonstratemysqli_character_set_name()Usage of the function (procedural style)-
//Establish connection $con = mysqli_connect("localhost", "root", "password", "mydb"); //Name of the character set $res = mysqli_character_set_name($con); print($res); //Close connection mysqli_close($con); ?>
Output result
utf8
In the object-oriented style, the syntax for this function is$con->character_set_name();.The following is an example of using this function in an object-oriented style;
<?php $con = new mysqli("localhost", "root", "password", "test"); //Name of the character set $res = $con->character_set_name(); print($res); //Close connection $con -> close(); ?>
Output result
utf8
Use mysqli_character_set_name() to get the default character set name
<?php $connection = mysqli_connect("localhost", "root", "password", "mydb"); if (mysqli_connect_errno($connection)){ echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $charset = mysqli_character_set_name($connection); echo "The default character set is: " . $charset; mysqli_close($connection); ?>
Output result
The default character set is: utf8