What encoding methods do you need to pay attention?

Source: Internet
Author: User
What encoding methods do you need to pay attention? There have been a lot of coding-related things involved in such a long web design. But today I encountered another garbled code, so I had to search for it and solve it.
Here are the encoding methods I know:
1.
(Notify the browser of the decoding method on this page)
2.
Encoding method for saving a document
3.
Database encoding method (set when defining a database or table)
4.
SQL statement encoding method (SET by "SET NAMES UTF8)

What is the final encoding method? In this case:
A static page transfers data from a text data box to another php page through the get method. This php page places the data in an insert statement and runs this SQL statement.
What is the encoding method of this query statement? Is it static page encoding, dynamic page encoding, or something else? Anyway, I set all to UTF-8, successfully inserted, no garbled. However, the problem is that the "set names UTF8" setting is required for each insert. how can we SET UTF8 to the default encoding method of SQL statements?

What else do we need to pay attention to the encoding method?


Reply to discussion (solution)

All "encoding methods" are based on the output page.

Mysql has the adaptive "encoding" function (it is not clear to other databases), that is, if you ask him to return the encoding, he will return the encoding.

The principle is: coding is required for almost every IO.
Loading php is one time, because the system/web server and php are two encodings.
Php output. the client system/browser and output characters are two encodings.
Read/write files, read/write databases, include ...... And so on.

I would like to mention a few more easily overlooked
Cookies. this is unlikely, but you should pay attention to it.
Session. I didn't test how to use a session together with two php codes. try again.
Sending and receiving, such as curl, socket, and API
Interaction with other languages
......

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.