PHP mysqli_set_charset() Function
In this chapter you will learn:
- Definition for PHP mysqli_set_charset() Function
- Syntax for PHP mysqli_set_charset() Function
- Parameter for PHP mysqli_set_charset() Function
- Return for PHP mysqli_set_charset() Function
- Example - sets the default character set
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//from 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);
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP mysqli_sqlstate() Function
- Syntax for PHP mysqli_sqlstate() Function
- Return for PHP mysqli_sqlstate() Function
- Example
Home » PHP Tutorial » PHP MySQLi Functions