note 61572 deleted from function.mysqli-set-charset by bjori

From: Date: Sun, 26 Mar 2006 12:27:21 +0000
Subject: note 61572 deleted from function.mysqli-set-charset by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-106628@lists.php.net to get a copy of this message
Note Submitter: feeling_zen ---- 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.

« previous php.notes (#106628) next »