Home >Backend Development >PHP Problem >How to set mysql character set in php

How to set mysql character set in php

王林
王林Original
2020-08-17 13:40:593313browse

How to set the mysql character set in php: You can use the mysqli_set_charset() function to set it. This function is used to specify the character set to be used when transmitting data to the database server. It returns true if successful and false if failed.

How to set mysql character set in php

Definition:

mysqli_set_charset() function specifies the default character set to be used when transmitting data to the database server, and returns if successful TRUE, or FALSE on failure.

(Recommended tutorial: php graphic tutorial)

Syntax:

mysqli_set_charset(connection,charset);

Parameter introduction:

  • connection Required. Specifies the MySQL connection to use.​

  • #charset Required. Specifies the default character set.

(Video tutorial recommendation: php video tutorial)

Implementation code:

Set the default client character set:

<?php 
// 假定数据库用户名:root,密码:123456,数据库:RUNOOB 
$con=mysqli_connect("localhost","root","123456","RUNOOB");
if (mysqli_connect_errno($con)) {
	echo "连接 MySQL 失败: " . mysqli_connect_error();
}
// 修改数据库连接字符集为 utf8
mysqli_set_charset($con,"utf8");
mysqli_close($con);
?>

The above is the detailed content of How to set mysql character set in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn