• PHP Video Tutorials

PHP mysqli_character_set_name() Function



Definition and Usage

The mysqli_character_set_name() function returns the name of the default character set of the current database connection.

Syntax

mysqli_character_set_name($con)

Parameters

Sr.No Parameter & Description
1

con(Mandatory)

This is an object representing a connection to MySQL Server.

Return Values

The mysqli_character_set_name() function returns a string value representing the name of the current character set.

PHP Version

This function was first introduced in PHP Version 5 and works works in all the later versions.

Example

Following example demonstrates the usage of the mysqli_character_set_name() function (in procedural style) −

//Creating a connection
$con = mysqli_connect("localhost", "root", "password", "mydb");
//Name of the character set
$res = mysqli_character_set_name($con);
print($res);
//Closing the connection
mysqli_close($con);
?>

This will produce following result −

utf8

Example

In object oriented style the syntax of this function is $con->character_set_name(); Following is the example of this function in object oriented style $minus;

<?php
   $con = new mysqli("localhost", "root", "password", "test");
   //Name of the character set
   $res = $con->character_set_name();
   print($res);
   //Closing the connection
   $con -> close();
?>

This will produce following result −

utf8

Example

<?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 "Default character set is: " . $charset;
   
   mysqli_close($connection);
?>

This will produce following result −

Default character set is: utf8
php_function_reference.htm
Advertisements