[Cppcms-users] CppDB with MySQL UTF8
Brought to you by:
artyom-beilis
From: 陈抒 <csf...@gm...> - 2011-09-11 12:37:39
|
To get the correct Chinese words from MySQL via CppDB,make sure you add ";set_charset_name=utf8" into connection string.There is one example below: #include <string> #include <iostream> using namespace std; #include <cppdb/frontend.h> int main(int argc,char* argv[]){ locale new_locale(locale("zh_CN.utf8")); locale old_loc = locale::global(new_locale); try{ string connection_string("mysql:host=192.168.1.15;database=d01;user=data;password=skst;set_charset_name=utf8"); cppdb::session session(connection_string); string sql="select address from tape_local limit 0,1"; cppdb::result res = session<<sql; while(res.next()){ cout<<res.get<string>("address")<<endl; } }catch(std::exception const& ex){ cout<<ex.what()<<endl; }catch(...){ cout<<"Unknown exception"<<endl; } } I also wrote one document in Chinese here: http://blog.csdn.net/sheismylife/article/details/6767770 陈抒 Best regards http://blog.csdn.net/sheismylife |