search
HomeBackend DevelopmentPHP ProblemWhat to do if php execution database is garbled

What to do if php execution database is garbled

What to do if php executes database garbled code

1. Add this sentence to the html code:

<metahttp-equiv content="”text/html;" charset="utf-8″">,</metahttp-equiv>This is used to define the encoding of the web page. When connecting to the database, select the specific database Finally, use mysql_qurry("set names utf8"); to set the database encoding to be consistent with the html encoding. The zend studio development environment is used. The development environment also has its own encoding for code display, so it also needs to be changed to utf8 format. Another one is also very critical when creating a database table. For example, in the phpMyAdmin database, when creating a tb_product table: you must also set the encoding method of the fields inside, and change Collation Set to utf8-general-ciEncoding

2. If you forget to set this attribute when creating the table, don’t worry, there is a way, first select the To modify the attribute table, click Operations to modify its attributes. At the same time, you can check changeall column and confirm. In order to further ensure that no garbled characters appear, you can also check a certain column in the table. Add utf8-general-ci to some fields or all fields respectively. Specific operation: Click on the table (tb_product)->Structure->check all->change that needs to be modified, and then set the Collation of each field individually.

Note: If you do not select the encoding for the entire table as utf8-general-ci, but only set some fields in the table to utf8-general-ci Format, if you check the properties of the table through Operation, you will still see that the encoding of the entire table is: For example, in the format of gbk-chinese-ci, if the Html encoding is utf8 , there will still be garbled characters, so the most important thing is to set the Collation of the entire table to utf8-general-ci. Although pro_name and pro_producer appear to be utf8-general-ci encoding, by looking at the encoding of the entire table, it is still in the gbk format. The encoding is inconsistent, so it is likely that garbled characters will still appear in the table.

Okay, let’s summarize, to make a long story short, four points:

1. If you write php, html# in zend studio ##Code, first change the display encoding format of the created project to utf8 format;

2. Use

html =”Content-Type” content=”text/html; charset=utf-8″>The encoding format for displaying the web page to be written;

3. Select a database when connecting to the database After (not the table) use

mysql_qurry("set names utf8");

4. As mentioned above, when creating the database, set the encoding format of the entire table to

utf8 -general-ci.

Recommended tutorial: "

php tutorial"

The above is the detailed content of What to do if php execution database is garbled. 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 Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MantisBT

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

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