开发者

Why some special characters like Ð and D has same identity in MySQL?

When i delete from table wh开发者_如何转开发ere name like Ð it removes all those items as well which contain D. Same case with many special characters, how to resolve this issue in mysql with php.


It depends on your collation, for instance:

mysql> SELECT 'é'= 'e' COLLATE utf8_general_ci;
+-----------------------------------+
| 'é'= 'e' COLLATE utf8_general_ci |
+-----------------------------------+
|                                 1 |
+-----------------------------------+
1 row in set (0.00 sec)

mysql> SELECT 'é'= 'e' COLLATE utf8_bin;;
+----------------------------+
| 'é'= 'e' COLLATE utf8_bin |
+----------------------------+
|                          0 |
+----------------------------+
1 row in set (0.00 sec)

You can set it per connection if you like:

mysql> SET collation_connection=utf8_bin;
Query OK, 0 rows affected (0.02 sec)

mysql> SELECT 'é'= 'e';
+-----------+
| 'é'= 'e' |
+-----------+
|         0 |
+-----------+
1 row in set (0.00 sec)

mysql> SET collation_connection=utf8_general_ci;
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT 'é'= 'e';
+-----------+
| 'é'= 'e' |
+-----------+
|         1 |
+-----------+
1 row in set (0.00 sec)


Change your column collation to utf8_bin.

Note that this will consider D and d different, as well.


Similar question here :

Php page can't recognize "ø" from mysql value

$mysql_set_charset("utf8");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜