PHP Programming Web pages cannot obtain all Chinese characters ?, However, the phpadmin database displays Chinese characters. $ Conn = mysql_connect ("localhost", "root", "1234") or die ("cannot connect to the database server:". mysql_connect_errror ());
Mysql_select_db ("messtest", $ conn );
$ Results = mysql_query ("select * from gbbook ");
Mysql_query ($ results, $ conn );
Mysql_query ("setnames 'utf8'", $ conn); // use Chinese encoding;
While ($ row = mysql_fetch_row ($ results )){
Echo $ row [0]. "". $ row [1]. "". $ row [2]. "". $ row [3]. "". $ row [4];
Echo"
";
}
Mysql_close ($ conn );
?>
Reply to discussion (solution)
Mysql_query ("set names 'utf8'", $ conn); // use Chinese encoding;
I tried it. it's useless.
Mysql_query ("setnames 'utf8'", $ conn); // use Chinese encoding;
Mysql_query ("setnames 'utf8'", $ conn );
Mysql_query ("set names 'gb2312 '", $ conn );
Mysql_query ("set names 'gbk'", $ conn );
I have tried all of them. they are useless! I use gb2312 in phpadmin;
Combine the browser and PHP files with gbk encoding, and add the following to the first line:
Header ("content-type: text/html; charset = gbk ")
You can see what encoding format is during your mysql installation (in the MySQL installation directory) my. find "default-character-set" in ini (there are two parts). if latin is changed to gbk or UTF-8, the supported Chinese encoding format can be gbk UTF-8.
// Add the following code if php does not include html code.
Header ("content-type: text/html; charset = gb2312") or header ("content-type: text/html; charset = gbk ")
// If both php and html code are included, add the following code.
Phpmyadmin is changed by yourself. you have to confirm the encoding of your program and your database. Unified.
It is best to confirm your database encoding and page display encoding. The encoding must be consistent.
After the above changes, I still cannot. there are other ways to do this. what is the problem ???
1. change latin to gbk in my. ini;
2. I used the database gb2312 and now changed it to gbk.
3. added the code page
No, please advise me again.
In general ..
1. character encoding of the page
2. character encoding of the database
3. read the character encoding set for the database code
If the three are consistent, no problem will occur.
Hi, I know what went wrong with you. This is your problem, but I have fixed it.
You have such a section: mysql_query ("setnames 'utf8'", $ conn); // uses Chinese Encoding. not only is it wrong, but you only set setnames to utf8 encoding, instead of the entire database. You should delete and add mysql_query ("set names utf8"); under mysql_query ($ results, $ conn.
I'm a newbie, and so are you.
I set the webpage to utf8, but my database field is set to gbk. There is no error, and the hacker can be read.
The page code should also be changed
Add
Header ("content-type: text/html; charset = utf-8 ");
Add database
Mysql_query ("set names 'utf8 '");
Mysql_query ("setnames 'utf8'", $ conn); // use Chinese encoding;
This sentence should be placed behind the database connection
$ Conn = mysql_connect ("localhost", "root", "1234") or die ("cannot connect to the database server:". mysql_connect_errror ());
Mysql_select_db ("messtest", $ conn );
Mysql_query ("setnames 'utf8'", $ conn); // use Chinese encoding;
...
...