Home  >  Article  >  Backend Development  >  How to solve mysql garbled code in php?

How to solve mysql garbled code in php?

烟雨青岚
烟雨青岚Original
2020-06-13 09:21:511913browse

How to solve mysql garbled code in php?

Solution to mysql garbled characters in php:

Add SET NAMES UTF8 after mysql_connect to eliminate garbled characters in UTF8 database. For GBK database, use SET NAMES GBK, the code is as follows:

$mysql_mylink = mysql_connect($mysql_host, $mysql_user, $mysql_pass); 
mysql_query("SET NAMES 'GBK'");

The database character set is utf-8

Use this for the connection statement:

mysql_query("SET NAMES 'UTF8'"); 
mysql_query("SET CHARACTER SET UTF8"); 
mysql_query("SET CHARACTER_SET_RESULTS=UTF8'");

Recommended tutorial: "php tutorial

The above is the detailed content of How to solve mysql garbled code 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
Previous article:What does $ in php mean?Next article:What does $ in php mean?