Delphi + ZeosLib + MySQL + UTF8 HowTo

Home Home
引用 | 编辑 笑笑
2008-06-13 09:02
楼主
推文 x0
最近公司的资料库要升级为 UTF-8 所以遇到了蛮多的问题,公司的管理系统是用 Delphi 开发的,而资料库是 MySQL,这几天好不容易把资料库由 big5 转为 utf-8 ,不过读进来都是乱码,后来在网路上找到一篇不错的教学,有用到的可以参考看看

转贴自

After fiddling around with all these components I finally made a working database connection with my server. It appears to me, that all connections made to MySQL 4.1 default to the "latin1" encoding no matter what the database contains. To work with utf8 you have to tell Zeos to set up certain server variables. You can do this by executing the SQL command: "SET character_set_connection=utf8; SET character_set_results=utf8;" Starting that moment, MySQL expects to get ALL commands in utf8 and will also return all datasets in utf8! You can put these variables into your TZConnection.Properties String list:

character_set_connection=utf8
character_set_results=utf8
Hint: If you want Mysql to use 100% utf8 internally, just add the following to your TZConnection.Properties:

character_set_client=utf8
character_set_connection=utf8
character_set_database=utf8
character_set_results=utf8
character_set_server=utf8
character_set_system=utf8
collation_connection=utf8_general_ci
collation_database=utf8_general_ci
collation_server=utf8_general_ci
Codepage=utf8
Now that MySQL is returning everything in utf8 you have to make sure to use WideString variables ALWAYS.
For NON-BLOB fields you can use the following:

VAR MyString : WideString;
VAR DBString : UTF8String;
[...]
DBString := MyTable.FieldByName( ..

访客只能看到部份内容,免费 加入会员



献花 x0
引用 | 编辑 highleekimo
2009-06-24 11:17
1楼
  
有没有中文教学

英文看不太懂 表情

献花 x0