Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that php mysql cannot query Chinese names

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces how to solve the problem that php mysql can not query Chinese names, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Php mysql can not query the Chinese name of the solution: 1, to ensure that MySQL and PHP code consistent; 2, in the php page header added "header (" Content-type: text/html; charset=utf-8 ");".

This article operating environment: Windows7 system, PHP7.1, Dell G3 computer.

What if php mysql cannot query Chinese names?

1. Ensure that the codes of MySQL and PHP are the same.

MySQL

Modify the coding format of the entire database

Note: if the data is not important, you can change the encoding format of the database directly, and then recreate the table. (the database in this example is test)

Alter database test character set utf8

Modify the coding format of the whole table

Note: if the data is important, execute the following code to convert the entire table encoding format to utf8 (in this case, the data table is students)

Alter table students convert to character set utf8

Modify the encoding format of sname field in students table

Note: the first sanme is to change the encoding format for the sname field in the table.

The second sname varchar (64) is the field name and field type to be modified (generally the same as in the original table, and will not be modified)

Not null is modified sname cannot be empty. (you can choose not to add)

Alter table students change sname sname varchar (64) character set utf8 not null

You can also use phpMyAdmin to enter the data table

Or access the database.

PHP

Add the following to the header of the php page

Header ("Content-type: text/html; charset=utf-8"); / / Note: you cannot output anything to the page before this sentence.

In addition, what is set in html is

two。 After getting the information passed by the search box, put in single quotation marks

Search box:

Enter a name:

Search

Xxx.php:$tofind = $_ POST ["userName"]; $sql = "SELECT * FROM user WHERE name='$tofind';"; $result = $conn- > query ($sql)

You can query Chinese character strings.

At least mine got it. ]

On how to solve the problem that php mysql can not query Chinese names is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report