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 of php insert mysql garbled code

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

Share

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

This article introduces the relevant knowledge of "how to solve the php insert mysql garbled problem". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Php insert mysql garbled solutions: 1, save the php page to UTF-8 encoding format; 2, use UTF8 format for data submission; 3, set "ENGINE=MyISAM DEFAULT CHARSET=utf8;" in the database.

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

How to solve the php insert mysql garbled problem?

Solution to the problem of Chinese garbled code when php is inserted into mysql database

Today, I reinstalled the system and reinstalled the running environment of PHP, but I didn't pay attention to it too much. I want to write something to review. When I used INSERT INTO to add data to the data table, I found that as long as the data was in Chinese, it was displayed in garbled code, so I stipulated in the web page that the language was found as gbk. I looked it up for a long time and made a summary:

The 1.php page should be saved in the UTF-8 encoding format.

2.php uses UTF8 for data submission.

3.MYSQL uses ENGINE=MyISAM DEFAULT CHARSET=utf8 when creating tables

For example (because I am too lazy to write, this example on the Internet feels quite clear):

Build a table:

Create TABLE `city` (`cityid` smallint (4) NOT NULL auto_increment, `cityname` varchar (80) NOT NULL default'', `provinceid` smallint (2) NOT NULL default '0mm, `inarea`varchar (5000) NOT NULL default'', `outarea`varchar (5000) NOT NULL default'', `tel`city` NOT NULL default'', PRIMARY KEY (`cityid`) ENGINE=MyISAM DEFAULT CHARSET=utf8

The code in PHP:

$conn=mysql_connect ("localhost", "user name", "password"); mysql_query ("set names' utf8'", $conn); mysql_select_db ("data name", $conn); $exec= "insert into net_city (cityname,inarea,outarea,tel) values ('". $link_cityname. ",'. $link_inarea.",'. $link_outarea. ",". $link_tel. "); $result=mysql_query ($exec,$conn) If ($result) {echo "1";} else {echo "0";} mysql_close ($conn); "how to solve the php insert mysql garbled problem" ends here. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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