int
mysql_set_character_set(MYSQL *mysql,
const char *csname)
该函数用于设置当前连接的默认字符集。该字符串csname
指定了一个有效的字符集名称。连接归类成为字符集的默认归类。此函数的工作方式与SET
NAMES
语句类似,但还会设置 的值
mysql->charset
,从而影响 所使用的字符集
mysql_real_escape_string()
MYSQL mysql;
mysql_init(&mysql);
if (!mysql_real_connect(&mysql,"host","user","passwd","database",0,NULL,0))
{
fprintf(stderr, "Failed to connect to database: Error: %s\n",
mysql_error(&mysql));
}
if (!mysql_set_character_set(&mysql, "utf8"))
{
printf("New client character set: %s\n",
mysql_character_set_name(&mysql));
}