In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you how to solve the problem that php can not write Chinese data into the database table, I believe most people do not know much about it, so share this article for your reference. I hope you will gain a lot after reading this article. Let's learn about it together.
The solution that php can not write Chinese data into database table is as follows: 1. Change the character set used in mysql to utf8;2, change the character set used in php file encoding to utf-8;3, and change the character coding used in front web pages to utf-8.
The operating environment of this paper: windows10 system, php 7&&mysql 5.0, thinkpad T480 computer.
In the process of learning PHP, we may encounter the situation that the Chinese data cannot be inserted into the data table, and the foreground web page cannot correctly display the Chinese data obtained from the database. When we encounter this problem, we need to change the character set used by mysql to the character set used by utf8,PHP file encoding to utf-8, and the character set used by the foreground web page to utf-8, which can solve the problem.
The specific steps are as follows:
1. Run MySQLInstanceConfig.exe under the MySQL installation directory, and configure the default code as utf8
Remember to select "Best Support For Multilingualism" and select "utf8" in the drop-down list below
After the configuration is completed, check the setting of "default-character-set" in the my.ini file under the MySQL installation path. It should already be set to utf8, if not, set to default-character-set=utf8.
2.1 specify the utf8 encoding when creating the database:
CREATE DATABASE database_nameCHARACTER SET "utf8" COLLATE "utf8_general_ci"
2.2 specify the utf8 encoding when creating the data table:
CREATE TABLE table_name (Column_name datatype,.) ENGINE=InnoDB DEFAULT CHARSET=utf8
3. Set the file encoding to utf-8
If you are using PhpStorm, the default file encoding is utf-8, which does not need to be changed
4. Set the character set of the page to utf-8:
5. You should mysql_query ('set names utf8') before operating on the data, and then perform queries, updates, inserts, and so on.
6. Finally, set the character set used by the client source data and the query result character set to gbk,:
SET character_set_client = gbk; / / when inserting Chinese data directly from the MySQL command line client, the stored data will not be garbled
SET character_set_results = gbk; / / the returned Chinese data from the MySQL command line client will not be garbled
The above is all the contents of this article entitled "how to solve the problem that php cannot write Chinese data to database tables". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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: 285
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.