PHP mysqli_set_charset () function
Set the default client character set:
<?php // 假定数据库用户名:root,密码:123456,数据库:w3big $con=mysqli_connect("localhost","root","123456","w3big"); if (mysqli_connect_errno($con)) { echo "连接 MySQL 失败: " . mysqli_connect_error(); } // 修改数据库连接字符集为 utf8 mysqli_set_charset($con,"utf8"); mysqli_close($con); ?>
Such operations in the Chinese characters is very useful for a lot of database query problem cases are garbled character set.
Definition and Usage
mysqli_set_charset () function is the default character set specified when the data transfer to the database server to use.
Note: Use this function on Windows platforms, you need MySQL client library version 4.1.11 or above (MySQL 5.0 requires 5.0.6 or later).
grammar
mysqli_set_charset( connection,charset ) ;
参数 | 描述 |
---|---|
connection | 必需。规定要使用的 MySQL 连接。 |
charset | 必需。规定默认字符集。 |
technical details
return value: | If successful it returns TRUE, on failure returns FALSE. |
---|---|
PHP version: | 5.0.5+ |
PHP MySQLi Reference Manual