Php writes mysql Chinese garbled characters. it Is utf8 and the php file is already UFT8,
$ Conn = mysql_connect ("localhost", "test", "test"); if (! $ Conn) {die ('could not connect :'. mysql_error ();} // mysql_query ("set test 'utf8'"); mysql_set_charset ("utf8", $ conn); // select the database mysql_select_db ("test ", $ conn); // INSERT data to the table mysql_query ("insert into test (id, myusername) VALUES (2, 'Chinese 2 ')"); // mysql_query ("insert into user (id, myusername) // VALUES (". intval ($ str_id ). ",". $ str_name. ")"); // Close the database connection mysql_close ($ conn );
Configure the database in phpmysql.
Why are you?
Reply to discussion (solution)
Mysql_query ("set names utf8 ");
Is the file code UTF-8?
I don't mean The encoding format of a file.
Php_mysql extension does not have the mysql_set_charset method
Php_mysqli has the mysqli_set_charset method.
In addition, you didn't provide garbled text.
If you have set up both databases, we recommend that you create a new database and try again ..
If you have set up both databases, we recommend that you create a new database and try again ..
I set everything, or? The final result is that all the new ones are playing well, that is, there is a problem with the previous build. haha, for your reference only. good luck to you.
Alter table users character set GBK; // modify the table
Alter table users modify username char (20) character set gbk; // modify the field
I have encountered Chinese garbled characters before. The first is the file encoding format, the second file parsing format, and whether the third Database supports Chinese characters.
Mysql_query ("set names utf8 ");
Thank you for choosing the correct answer.