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/* w  ww  . j a va2 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);
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions