iT邦幫忙

0

Visual Studio Community 2017 C++與MariaDB/MySQL中文插入亂碼決解方法

  • 分享至 

  • xImage
  •  

我的Windows 7 Pro是英文版, 但系統位置是Taiwan, 使用的格式是Chinese (Traditional, Taiwan), 在"Region and Language"中的設定, 在Visual Studio Community 2017寫C++與MariaDB/MySQL insert中文出現亂碼.

在Visual Studio中的設定為:

  1. 在Visual Studio裡要設定使用Windows相同語言: Tools->Options->Environment->International Settings->Language: Same as Microsoft Windows. Restart Visual Studio
  2. 在專案裡要設定支援多字元: Project->Properties->General->Character Set: Use Multi-Byte Character Set.
  3. 在C++裡要加入:
    if (!mysql_set_character_set(mycon, "big5"))
    printf("New client character_set: %s\n", mysql_character_set_name(mycon));

在MariaDB/MySQL的設定為:
MariaDB [file_index]> show variables like "character_set%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言