Solution to Chinese garbled characters in PHP database: 1. When creating the database, specify the character type as uft8; 2. When creating the table, specify the character type as utf8; 3. In PHP's MySQL connection function, add statements "mysql_query("set names 'utf8'");".
Recommendation: "PHP Video Tutorial"
To solve the problem of PHP database garbled code, you can make the following settings:
1. Settings in the database:
(1). When creating a new database in MYSQL, the database selects UTF-8 encoding and the character set is set to utf-8_unicode_ci (Unicode (multi-language), size-insensitive Write), the collation of the table in the library is set to utf-8_general_ci; the collation of each field in the table is set to
utf-8_general_ci
## .When creating a database, specify the character type to be uft8, such as:create database db_name character set utf8;or modify the created database to utf8 type:
alter database db_name character set utf8;For example:
CREATE TABLE tb_name( id int(10) NOT NULL auto_increment, username char(34) NOT NULL , password int(56) NOT NULL, PRIMARY KEY (id) ) DEFAULT CHARSET=utf8;or modify the created table to utf8 format:
alter table tb_name character set utf8;or modify a field in the table to utf8 format
alter table tb_name modify type_name varchar(50) CHARACTER SET utf8;2. Settings during PHP connection, In the MySQL connection function of PHP, add the statement:
//注意此处为utf8,不要写成utf-8 mysql_query("set names 'utf8'");3. Page declaration code: In the HTML code xxx, you can use
Declare page encoding
4. Set the browser to utf-8 Format. 5. Editor character encoding, the code document must be saved in utf-8 format. 6. If the inserted data is garbled, you can transcode the inserted data. First convert the string to utf-8 and then insert it into the database.The above is the detailed content of Solution to Chinese garbled characters in PHP database. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1
Easy-to-use and free code editor

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools
