In-depth understanding of the differences between mysqlSETNAMES and mysql (I) _ set_charset _ MySQL
Source: Internet
Author: User
To better understand the differences between mysqlSETNAMES and mysql (I) _ set_charset bitsCN.com, try to use mysqli_set_charset (mysqli: set_charset) instead of "SET NAMES". of course, this content is also described in the PHP Manual, but I didn't explain why.
Recently, several friends asked me this question. why?
When there are too many people to ask, I think I can write a blog to introduce this part of content.
First, many people do not know what "set names" is,
In my previous articles, I went deep into MySQL character set settings and introduced the "environment variables" of character_set_client/character_set_connection/character_set_results,
These three variables respectively tell the MySQL server, the client's replica set, the replica set when it is transmitted to the MySQL server, and the replica set that expects the results returned by MySQL.
For example, by using "set names utf8", I will tell the server that I am using UTF-8 encoding. I hope you will also return the UTF-8 encoding query results to me.
Generally, it is enough to use "set names" to ensure the correctness. Why does the manual recommend mysqli_set_charset (PHP> = 5.0.5?
First, let's take a look at what mysqli_set_charset has done (note that mysql_set_charset is similar to the asterisk annotation ):
What is the role of charset, a member of the mysql core structure?
This tells us about mysql_real_escape_string (). The difference between this function and mysql_escape_string is that it considers the "current" character set. Where can this current character set come from?
By the way, you guessed it was mysql-> charset.
Mysql_real_string in the determination of wide character set characters, according to the member variables to adopt different policies, for example, if it is UTF-8, then libmysql/ctype-utf8.c will be used.
Check the instance. the default mysql connection character set is latin-1 (classic 5c problem ):
$ Db = mysql_connect ('localhost: 100', 'root', '123 ');
Mysql_select_db ("test ");
$ A = "/x91/x5c ";//"
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.