(PHP 5 >= 5.0.5, PHP 7)
mysqli::set_charset -- mysqli_set_charset — 锟斤拷锟斤拷默锟斤拷锟街凤拷锟斤拷锟斤拷
锟斤拷锟斤拷锟斤拷锟斤拷锟�
$charset
) : bool锟斤拷锟教伙拷锟斤拷锟�
锟斤拷锟斤拷锟斤拷锟斤拷锟捷匡拷浯拷锟斤拷址锟绞憋拷锟斤拷玫锟侥拷锟斤拷址锟斤拷锟斤拷搿�
link
锟斤拷锟皆癸拷锟教伙拷锟斤拷式锟斤拷锟斤拷mysqli_connect() 锟斤拷 mysqli_init() 锟斤拷锟截碉拷锟斤拷锟接憋拷识锟斤拷
charset
锟斤拷锟斤拷为默锟较碉拷锟街凤拷锟斤拷锟斤拷锟斤拷锟斤拷
锟缴癸拷时锟斤拷锟斤拷 TRUE
锟斤拷 锟斤拷锟斤拷锟斤拷失锟斤拷时锟斤拷锟斤拷 FALSE
锟斤拷
Note:
锟斤拷锟斤拷锟絎indows平台锟斤拷使锟矫该凤拷锟斤拷锟斤拷锟斤拷要4.1.11锟斤拷锟斤拷锟斤拷系锟組ySQL锟酵伙拷锟剿库,锟斤拷MySQL锟芥本为5.0.6锟斤拷锟较★拷
Note:
锟斤拷应锟斤拷锟斤拷锟斤拷选锟斤拷锟斤拷锟节改憋拷锟街凤拷锟斤拷锟斤拷姆锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟绞癸拷锟�mysqli_query()执锟斤拷SQL锟斤拷锟斤拷锟�SET NAMES ...锟斤拷锟斤拷 SET NAMES utf8锟斤拷锟斤拷 锟斤拷锟�MySQL锟街凤拷锟斤拷锟侥革拷锟斤拷
Example #1 mysqli::set_charset() example
锟斤拷锟斤拷锟斤拷锟斤拷锟�
<?php
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* change character set to utf8 */
if (!$mysqli->set_charset("utf8")) {
printf("Error loading character set utf8: %s\n", $mysqli->error);
} else {
printf("Current character set: %s\n", $mysqli->character_set_name());
}
$mysqli->close();
?>
锟斤拷锟教伙拷锟斤拷锟�
<?php
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'test');
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
/* change character set to utf8 */
if (!mysqli_set_charset($link, "utf8")) {
printf("Error loading character set utf8: %s\n", mysqli_error($link));
} else {
printf("Current character set: %s\n", mysqli_character_set_name($link));
}
mysqli_close($link);
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
Current character set: utf8