Home > Article > Backend Development > How to set the MySQL connection character set in php
Character is a general term for various characters and symbols, including characters of various countries, punctuation marks, graphic symbols, numbers, etc. Character set(Character set) is a collection of multiple characters. There are many types of character sets. Each character set contains a different number of characters. Common character set names: ASCII character set, GB2312 character set, BIG5 Character set, GB18030 character set, Unicode character set, etc. In order for a computer to accurately process text in various character sets, character encoding is required so that the computer can recognize and store various text. There are a large number of Chinese characters, and they are divided into two kinds of characters, Simplified Chinese and Traditional Chinese, with different writing rules. Computers were originally designed based on English single-byte characters. Therefore, encoding Chinese characters is the technical basis for Chinese information exchange. .
I always used mysql_query("SET NAMES 'utf8'"); to set the default connection for MySQL Character set; but today I found a PHP recommendation The replacement for this method is the function
mysql_set_charset() that sets the MySQL connection character set.
This function is used like this:
mysql_set_charset('utf8', $link);
Returns TRUE on success and FALSE on failure.
The above is the detailed content of How to set the MySQL connection character set in php. For more information, please follow other related articles on the PHP Chinese website!