Home > Backend Development > PHP Tutorial > PHP shows that the garbled database encountered is mysql

PHP shows that the garbled database encountered is mysql

巴扎黑
Release: 2016-11-10 09:32:38
Original
1315 people have browsed it

I encountered the problem of garbled characters when using PHP+MYSQL. The solution:

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

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

The database character set is utf-8

Use this for the connection statement

1 mysql_query("SET NAMES 'UTF8'");
2 mysql_query("SETCHARACTERSET UTF8");
3 mysql_query("SET CHARACTER_SET_RESULTS=UTF8'");


Related labels:
php
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