有趣的是,这段代码对我不起作用:
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'test');
mysqli_set_charset($link, "utf8");
printf("Current character set: %s\n", mysqli_character_set_name($link));
//shows latin1
但是,在条件内设置字符集是有效的:
if (!mysqli_set_charset($link, "utf8")) {
printf("Error loading character set utf8: %s\n", mysqli_error($link));
exit();
} else {
printf("Current character set: %s\n", mysqli_character_set_name($link));
//shows utf8
}
我的设置:
$ rpm -qa|grep -E "php|maria"
mariadb-5.5.56-2.el7.x86_64
mariadb-server-5.5.56-2.el7.x86_64
mariadb-libs-5.5.56-2.el7.x86_64
php-pdo-5.4.16-45.el7.x86_64
php-cli-5.4.16-45.el7.x86_64
php-5.4.16-45.el7.x86_64
php-common-5.4.16-45.el7.x86_64
php-mysql-5.4.16-45.el7.x86_64