#30477 [Opn]: UTF-8 characters are changed by mysql_query
| From: | stian at grytoyr dot net | Date: | Tue, 19 Oct 2004 11:00:46 +0000 |
| Subject: | #30477 [Opn]: UTF-8 characters are changed by mysql_query | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-67760@lists.php.net to get a copy of this message | ||
ID: 30477
User updated by: stian at grytoyr dot net
Reported By: stian at grytoyr dot net
Status: Open
Bug Type: MySQL related
Operating System: SuSE Linux 9.1 Professional
PHP Version: 5.0.2
New Comment:
Oh, and an example of the output I'm seeing with the code in the
"reproduce" section can be viewed here:
http://klara.grytoyr.net/tmp/bug.php
Previous Comments:
------------------------------------------------------------------------
[2004-10-19 11:36:42] stian at grytoyr dot net
Description:
------------
I'm using PHP 5.0.2, MySQL 4.1.6gamma and Apache 2.0.49-27.16 on SuSE
Linux Professional 9.1. PHP has been compiled by me, MySQL is a binary
distribution from MySQL, Apache is the SuSE default.
When I submit a query containing a UTF-8 representation (hex
value 0xC48D) of the Unicode character č (lowercase c with caron)
to the MySQL server using mysql_query, sniffing the network traffic
reveals that the character is sent as 0xC43F, which is not a valid
UTF-8 character.
It's important to note that this happens BEFORE the data reaches the
MySQL server, so I believe it must be a PHP problem.
Some other Unicode characters are also problematic, including Đ
and Á, but they are both sent as 0xC33F.
The MySQL table has been created with CHARACTER SET utf8.
I don't think this bug is possible to reproduce without running
mysql_query, so the code below requires a connection to a MySQL
database.
This _may_ be a duplicate of Bug #28231, but I'm not entirely sure.
Reproduce code:
---------------
header("Content-Type: text/html; charset=UTF-8");
// connect to a mysql database which supports UTF-8 here
$testStr = chr(196) . chr(141); // Unicode character č (c caron)
echo '$testStr before query: ' . $testStr . '<br />'; // will output
the correct UTF-8 character (c caron)
echo 'hex of $testStr before query: ' . bin2hex($testStr) . '<br />';
// will output c48d
$updateResult = mysql_query("update klara_test set klara_text =
'$testStr' where klara_id = 1", $conn);
$fetchResult = mysql_query("select klara_text from klara_test",
$conn);
while ($myrow = mysql_fetch_array($fetchResult)) {
echo '$testStr from database: ' . $myrow['klara_text'] . '<br
/>'; //
will output gibberish
echo 'hex of $testStr from database: ' .
bin2hex($myrow['klara_text']) . '<br />'; // will output c43f
}
Expected result:
----------------
I would expect the UTF-8 characters to remain unchanged.
Actual result:
--------------
Certain Unicode characters are altered by mysql_query, as far as I can
tell.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=30477&edit=1