Process utf-8 data from MySQL in C++ and give result back

后端 未结 1 789
盖世英雄少女心
盖世英雄少女心 2020-12-18 15:03

I just simply want to know - how to get MySQL results to C++ in string (or another similar \"string\" datatype) in a way that would not deform data

相关标签:
1条回答
  • 2020-12-18 16:04

    From MySQL Reference

    mysql_options() should be called after mysql_init() and before mysql_connect() or mysql_real_connect().

    So your code should be

      mysql_init(&mysql);    
      mysql_options(&mysql, MYSQL_SET_CHARSET_NAME, "utf8"); 
      mysql_options(&mysql, MYSQL_INIT_COMMAND, "SET NAMES utf8"); 
    
      mysql_real_connect(&mysql,CTH_SERVER,CTH_USER,CTH_PASSWORD,CTH_DB_IN,0,0,0)); 
    
    0 讨论(0)
提交回复
热议问题