After "SETNAMESUTF8" is used, garbled code is used to solve the problem.

Source: Internet
Author: User
When & quot; SETNAMESUTF8 & quot; is used, garbled characters occur. in the past, mysql_query (& quot; SETNAMESUTF8 & quot;) was not used in the program ;), I am not very clear about the role of this line of code. I added this sentence to the code, but I found that the previously inserted data is garbled after this sentence is added, however, after this sentence is added, the inserted data displays garbled characters after "set names UTF8" is used.
This is the problem. in the past, mysql_query ("set names UTF8") was not used in the program. I am not very clear about the role of this line of code. I added this sentence in the code, however, after this sentence is added, the previously inserted data is garbled, but after this sentence is added, the inserted data is displayed normally, because I have inserted a lot of content after adding this code, so I don't want to delete it. is there a solution? Can data before and after mysql_query ("set names UTF8") be displayed normally?

------ Solution --------------------
Transcode the previous data.
------ Solution --------------------
PHP code
Transcode the data retrieved from the database: $ newdata = iconv ("GBK", "UTF-8", $ data );
------ Solution --------------------
Discussion
My program has a lot of operations on the database, and it will be very troublesome to transcode one by one!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.