The mysqli_set_charset() function sets the default character set.
PHP mysqli_set_charset() Function has the following syntax.
mysqli_set_charset(connection,charset);
Parameter | Is Required | Description |
---|---|---|
connection | Required. | MySQL connection to use |
charset | Required. | Default character set |
It returns TRUE on success. FALSE on failure.
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);
?>