PHP Tutorial - PHP mysqli_set_charset() Function






Definition

The mysqli_set_charset() function sets the default character set.

Syntax

PHP mysqli_set_charset() Function has the following syntax.

mysqli_set_charset(connection,charset);

Parameter

ParameterIs RequiredDescription
connectionRequired.MySQL connection to use
charsetRequired.Default character set

Return

It returns TRUE on success. FALSE on failure.

Example

Sets the default character set


<?php/*from  w w  w. j  av a  2  s.  c o m*/
    $con=mysqli_connect("localhost","my_user","my_password","my_db");

    if (mysqli_connect_errno($con)){
       echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    
    // Change character set to utf8
    mysqli_set_charset($con,"utf8");
    
    mysqli_close($con);
?>