What to do if php executes database garbled code
1. Add this sentence to the html code:
<metahttp-equiv=”Content-Type” content=”text/html; charset=utf-8″>,
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-ci
Encoding
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;
html =”Content-Type” content=”text/html; charset=utf-8″>The encoding format for displaying the web page to be written;
mysql_qurry("set names utf8");
utf8 -general-ci.
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!