search
HomeBackend DevelopmentPHP ProblemWhat should I do if php sends garbled strings to the mysql database?

Solution for php to pass garbled strings to the mysql database: 1. Check the database encoding method through "show variables like 'character%';"; 2. Set it through "set character_set_server = 'utf8';" Just encode it as utf8.

What should I do if php sends garbled strings to the mysql database?

The operating environment of this tutorial: Windows 10 system, PHP version 8.1, DELL G3 computer

php passes characters into the mysql database What to do if a string of garbled characters appears?

PHP inserts Chinese into the mysql database and displays garbled characters

The garbled characters are as follows:

What should I do if php sends garbled strings to the mysql database?

##Solution

View Database encoding method:

//查询
show variables like 'character%';
//设置
set character_set_server = 'utf8';

What should I do if php sends garbled strings to the mysql database?

Set HTML page encoding

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

PHP file encoding setting

//消息头部
header("Content-Type:text/html; charset=utf-8");
//数据库连接方式
$conn = new mysqli($servername,$username,$password,$dbname);
mysqli_set_charset($conn,&#39;UTF8&#39;);
//注意,下面这种方式不行!!!
$conn = new mysqli($servername,$username,$password,$dbname);
mysqli_query(“set names utf8”);

Related introduction:

UTF-8 (8-bit, Universal Character Set/Unicode Transformation Format) is a variable-length character encoding for Unicode. It can be used to represent any character in the Unicode standard, and the first byte in its encoding is still compatible with ASCII, so that the original software that processes ASCII characters can continue to be used without or with only a few modifications. Therefore, it has gradually become the preferred encoding for email, web pages, and other applications that store or transmit text.

Recommended learning: "

PHP Video Tutorial"

The above is the detailed content of What should I do if php sends garbled strings to the mysql database?. 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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function