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
Parameter | Is Required | Description |
---|---|---|
connection | Required. | MySQL connection to use |
charset | Required. | 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);
?>