Home  >  Article  >  Database  >  Linux C编程向MySQL里插入中文数据乱码

Linux C编程向MySQL里插入中文数据乱码

WBOY
WBOYOriginal
2016-06-07 17:27:481233browse

Linux C编程向MySQL里插入中文数据乱码解决方案。 先看《Linux下MySQL的中文不能显示及sock链接错误问题解决》这篇文章 http://w

Linux C编程向MySQL里插入中文数据乱码解决方案。

先看《Linux下MySQL的中文不能显示及sock链接错误问题解决》这篇文章

像上面这样更改后,,在C程序里向数据库插入数据之前,应该加上这一句:

mysql(conn,"set names \'utf8\' ");

这样就不会产生乱码了。

character_set_client:客户端的字符集

character_set_results:结果字符集

character_set_connection:连接字符集

设置这三个系统参数的命令:set names ‘utf8’

这三个系统参数的作用:

信息输入路径: client--connection--server (数据传送方向从左到右)

信息输出路径: server--connection--results (数据传送方向从左到右)

故这几个系统参数的值须相同,不然以不同的编码方式传送数据,若编码方式不兼容,则容易造成乱码的问题。

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn