What I read from the database about garbled characters is ?????

Source: Internet
Author: User

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

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.