How to set mysql character set in php

王林
Release: 2023-03-04 16:16:02
Original
3269 people have browsed it

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);
Copy after login

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);
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template