note 61572 added to function.mysqli-set-charset
| From: | feeling_zen at osu1 dot php dot net | Date: | Tue, 07 Feb 2006 05:08:17 +0000 |
| Subject: | note 61572 added to function.mysqli-set-charset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103157@lists.php.net to get a copy of this message | ||
An embarrasing correction to my last note. To set the connection character set between PHP and MySQL
the query below
$query="SET character_set_client=utf8";
was incorrect. It stops error output but corrupts your data by accepting LATIN1 but assuming it to
be UTF8 (Doh!). The correct query is:
$query="SET CHARACTER SET utf8";
Which sets the connection encoding to UTF8 and the connection collation to whatever the MySQL server
uses. Using SET NAMES='utf8' also does this but overrides the server's collation.
By using "SET CHARACTER SET {charset}" right after opening your connection to the database
you can make sure input data and SQL string comparisons don't produce unexpected results.
Obviously the same applies for other character sets besides UTF8. So for Japanese it is either SJIS
or ISO-2022-JP.
----
Server IP: 61.195.146.164
Probable Submitter: 218.219.202.171
----
Manual Page -- http://www.php.net/manual/en/function.mysqli-set-charset.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61572
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61572&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61572&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61572&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61572&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61572&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61572&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61572&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61572&report=yes
Search -- http://master.php.net/manage/user-notes.php