Set the default client character set:
<?php // Assume database username: root, password: 123456, database: CODERCTO $con=mysqli_connect("localhost","root","123456","CODERCTO"); if (mysqli_connect_errno($con)) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // Modify the database connection character set to utf8mysqli_set_charset($con,"utf8");mysqli_close($con);?>This kind of operation is very useful for Chinese characters. Many garbled database queries are caused by character set problems.
The mysqli_set_charset() function specifies the default character set to be used when transferring data to and from the database server.
Note: To use this function on the Windows platform, you need MySQL client library version 4.1.11 or above (MySQL 5.0 requires version 5.0.6 or above).
mysqli_set_charset( connection,charset ) ;
| parameter | describe |
|---|---|
| connection | Required. Specifies the MySQL connection to use. |
| charset | Required. Specifies the default character set. |
| Return value: | Returns TRUE if successful and FALSE if failed. |
|---|---|
| PHP version: | 5.0.5+ |