MySQLi - Set Charset
语法
bool mysqli_set_charset ( mysqli $link , string $charset )
定义和用法
它设置默认的客户端字符集。
示例
试试下面的例子 −
<?php $servername = "localhost:3306"; $username = "root"; $password = ""; $dbname = "TUTORIALS"; $tmp = NULL; $conn = new mysqli($servername, $username, $password, $dbname); if (!$conn->real_connect($servername, $username, $password, $dbname)) { die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); } echo 'Success... ' . mysqli_get_host_info($conn) . " "; printf("character set: %s ", $conn->character_set_name()); if (!$conn->set_charset("utf8")) { printf("Error loading character set utf8: %s ", $conn->error); exit(); } else { printf("Current character set: %s ", $conn->character_set_name()); } $conn->close(); ?>
上述代码的示例输出应该是这样的 −
Success... localhost:3306 via TCP/IP character set: latin1 Current character set: utf8