PDF (US Ltr) - 1.4Mb
PDF (A4) - 1.4Mb
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));
}