我的mysql数据库用的是 utf8字符集,现在我要用
std::string com ="insert into `svpnrc`(`id`,`name`,`rc_grp_id`,`ip_from`,`ip_to`,`port_from`,`port_to`) values ( '30','士大夫啊','123','123','123','123','123');";
int r = mysql_query(hnd,com.c_str());
执行一条插入语句,插入时成功了 可是name字段显示的是乱码,我将com先转换成utf8格式的,在插入可是显示的是一模一样,由asii转换成utf8是正确的,请问我如果要插入 中文字符我该如何处理
std::string com ="insert into `svpnrc`(`id`,`name`,`rc_grp_id`,`ip_from`,`ip_to`,`port_from`,`port_to`) values ( '30','士大夫啊','123','123','123','123','123');";
int r = mysql_query(hnd,com.c_str());
执行一条插入语句,插入时成功了 可是name字段显示的是乱码,我将com先转换成utf8格式的,在插入可是显示的是一模一样,由asii转换成utf8是正确的,请问我如果要插入 中文字符我该如何处理
解决方案 »
- A机器IP是192.168.78.101,B机器IP是210.76.32.102,现在在A机器上远程为B机器安装MYSQL,怎样安装?安装的时候怎样设置?
- mysql复制的问题
- 如何把多个txt的内容批量导入到mysql中
- 数据库树结构结果集合遍历性能问题
- 請問在windows下如何連接linux下的MYSQL請大家推荐几個好工具﹐不知道有沒有
- mysql如何获得自增字段下一个值
- 谁知道在MySQL4.1.7+Tomcat5.0.19+JDBC3.08下成功连接数据库吗?
- 我在redhat9上面安装mysql-standard-4.1.7
- 100分求解----MYSQL中文问题
- MySQL官方手册(中文)?
- 关于tinyint类型字段
- 连接MySQL数据库问题。为什么在第二个函数中con说是java.lang.NullPointException?
std::string com ="insert into `svpnrc`(`id`,`name`,`rc_grp_id`,`ip_from`,`ip_to`,`port_from`,`port_to`) values ( '30','士大夫啊','123','123','123','123','123');";
int r = mysql_query(hnd,com.c_str());
关于字符集你可以参考一下这个贴子。
http://blog.csdn.net/ACMAIN_CHM/archive/2009/05/12/4174186.aspx
贴结果
mysql> show variables like 'char%';
+--------------------------+-----------------
| Variable_name | Value
+--------------------------+-----------------
| character_set_client | latin1
| character_set_connection | latin1
| character_set_database | latin1
| character_set_filesystem | binary
| character_set_results | latin1
| character_set_server | latin1
| character_set_system | utf8
| character_sets_dir | C:\Program Files
+--------------------------+-----------------
8 rows in set (0.00 sec)mysql>2。 看一下你这个表的字符集设置。
show create table svpnrc;
`id` int(11) DEFAULT NULL,
`name` varchar(100) DEFAULT NULL,
`rc_grp_id` int(11) DEFAULT NULL,
`ip_from` int(11) DEFAULT NULL,
`ip_to` int(11) DEFAULT NULL,
`port_from` int(11) DEFAULT NULL,
`port_to` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8
std::string com ="insert into `svpnrc`(`id`,`name`,`rc_grp_id`,`ip_from`,`ip_to`,`port_from`,`port_to`) values ( '30','士大夫啊','123','123','123','123','123');";
int r = mysql_query(hnd,com.c_str()); 我在执行mysql_query前都有加mysql_query(hnd,"set names 'utf8'"); 现在关键的问题是 中文字符会出现'/0'的字符,使sql语句自动截断 从而执行不成功
我都是set names 'gbk'