Get default character set for the database connection in PHP

Description

The following code shows how to get default character set for the database connection.

Example


  //from  w w w.j  a  v a 2 s  .  c o m
<?php
    $con=mysqli_connect("localhost","root","","test");
    // Check connection
    if (mysqli_connect_errno()){
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
   
    $charset=mysqli_character_set_name($con);
    echo "Default character set is: " . $charset;
   
    mysqli_close($con);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    MySQL »




MySQLi
MySQLi Object Oriented