Younger brother is always a careless person. It took me 6 hours to get a statement...
I hope you can learn from it ......
Look at the red part. The example is in the book, but there is no red sentence.
It is also a long time to find information to know how to do this.
Please refer to the source code:
1 <?php
2
3 $link=mysql_connect("localhost","root","root");
4Mysql_query ("set names 'utf8'"); // no such sentence will be displayed on the page ????
5 if (! $ Link)
6 {
7. echo "database connection failed! ";
8} else {
9
10 mysql_select_db ("db_student ");
11 $ SQL = "select * from student ";
12
13
14 $ result = mysql_query ($ SQL );
15 $ row = mysql_fetch_row ($ result );
16 echo "No.:". mysql_result ($ result, 0, "student. id"). "<br/> ";
17 echo "name:". mysql_result ($ result, 0, "student. name"). "<br/> ";
18 echo "Gender:". mysql_result ($ result, 0, "sex"). "<br/> ";
19 echo "age:". mysql_result ($ result, 0, "age"). "<br/> ";
20}
21 mysql_close ();}
Effect:
Effect of unspecified encoding:
Encoded:
Personal perception:
Although it was a php project, my younger brother worked on the project for a few months and found that the language was actually a tool (the younger brother learned Java, but he was caught by the teacher to do the php project .... ~~~~ (>_< )~~~~ )
The core is thinking,
So I understand what development experience is.
For example, if you do not understand Java, but you have a project development experience,
There will be fewer detours,
Because many ideas are the same, but the implementation (statement) methods are different!
Like this problem,
Next time I guess I can solve it all at once .!!!
I hope to help you.
Which of the following is from the Internet.
Use mysq_query to set the encoding when connecting to the database using php.
Syntax: mysql_query ("set names 'utf8 '");
For example:
Reference content is as follows: $ Conn = mysql_connect ('127. 0.0.1 ', 'root', '123 '); Mysql_query ("set names 'utf8'", $ conn); // fix garbled characters Mysql_select_db ('test1', $ conn ); |
This connection is very detailed.
Http://www.phperz.com/php/introduction/03211UR0091858.html