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!