Objective:
To tell you the truth,
Sandals also think UTF8 is a good thing ...
After all, the same screen shows the attractiveness of Japan and Korea to East Asians is not small ...
(Of course the benefits are not just this ... )
Not only the Web program ...
Many application kernels are beginning to use Unicode encoding ...
The purpose is obvious: support multi-lingual display ...
All Microsoft software is Unicode kernel ...
So Japanese software to get your Chinese XP on the normal display ...
And the Chinese 98 will be because the GB kernel installs other language software to cause garbled characters ...
As for UTF8,
Can be said to be a branch of Unicode,
It saves a Chinese character in three bytes ...
(Unicode with four bytes)
Application software has collectively defected to Unicode ...
We're not allowed to use UTF8 for Web programming?
In this article, the sandals as far as possible to introduce the UTF8 code PHP (as the mainstream development language now) programming ...
As for why the "Chinese" is introduced separately ...
One is because English this thing really does not need to consider UTF8 ...
Unless you're prepared to do more language systems ...
(I would like to complain: now the foreigner writing programs do not pay attention to this problem ...) )
The other is the Chinese and Japanese South Korea and other multi-byte language in the UTF8 code processing method is actually similar ...
According to gourd painting scoop can ...
Good...... Let's start with the database Processing section ...
==========================================
Connecting to a database
A lot of people just upgraded to MySQL (and the best combination of PHP) 4.1 will find that data is out of date ...
This is because MySQL (the best combination with PHP) supports the character set starting from 4.1 ...
and the default character set is UTF8 ...
(Full proof of the importance of international integration ...) Hey...... )
In the past, most of us used UTF8 or GBK coding ...
In this way the output of data is of course garbled ...
To solve garbled characters ...
You have to let the program know what encoding data to get ...
We assume that your previous database is UTF8 encoded ...
Then you can add a sentence before the query
MySQL (and PHP collocation best combination) _query (set CHARACTER set UTF8) or Die ("Query failed:".) MySQL (and PHP collocation of the best combination) _error ());
Of course, because more than 4.1 of the need for such treatment,
So we can add judgment:
$MySQL (best combination with PHP) Version = $db->query_first ("select version () as version");
if ($MySQL (best combination with PHP) Version[version] >= 4.1)
{
MySQL (and PHP collocation best combination) _query (set CHARACTER set UTF8) or Die ("Query failed:".) MySQL (and PHP collocation of the best combination) _error ());
}
In this way, regardless of MySQL (and PHP collocation of the best combination) The default encoding is what can be properly accessed ...
(Whether you are alive or not, even installment are not a problem bird ...) )
However, people are international birds ...
Are you still using UTF8?
How do I transcode it?
And also......
Data upgrade when garbled what to do?
Cold!
And listen to tell ...
============================================
Data upgrade to 4.1
To upgrade ...
You have to export first ...
To say that foreigners are really not responsible ...
The previous export method always loses some Chinese characters ...
For example, "I love your Mother" to make "I love You" ...
(usually the word at the end of a piece of data is lost)
The whole poor one generation ...
(with the words of the pomegranate elder sister is "so heresy thing is too exciting" ... )
To protect your fragile heart ...
Also in order to uphold the Chinese traditional ethics and morality ...
You can change the field of the data containing Chinese characters to binary (binary) encoding ...
Concrete Method ...
You can run this statement:
ALTER table ' table name ' CONVERT to CHARACTER SET binary;
In this way, those character type fields, such as:
CHAR, VARCHAR, and TEXT
will be converted to
BINARY, VARBINARY, and BLOB
Then export and import into the 4.1 environment ...
The last tedious task, of course, is:
You need to change their type back ...
There is an upgrade to 4.1 ...
Of course, there is a downward downgrade ...
How to downgrade???
Sandals to the last toilet ...
And you please turn down the page ...
=============================================
Data degraded from 4.1
Someone found that the SQL file exported from 4.1 Failed to import the lower version of the program ...
The problem is really simple ...
and MySQL (and the best combination of PHP collocation) has been thinking for us all ...
When exporting, add the –compatible parameter ...
Let's assume that your database is UTF8 encoded ...
and the target database version is 4.0 ...
So the command line reads:
Shell>mysql (best combination with PHP) dump--user=username--password=password--compatible=mysql (best combination with PHP) 40-- Default-character-set=utf8 Database > Db.sql
The exported SQL file will be able to import the lower version of the database successfully ...
http://www.bkjia.com/PHPjc/508616.html www.bkjia.com true http://www.bkjia.com/PHPjc/508616.html techarticle to tell the truth, Sandals also think UTF8 is a good thing ... After all, the same screen shows the attractiveness of Japan and Korea to East Asians is not small ... (Of course the benefits are not just this ... ) Not only ...