首页 > 代码库 > debug $mysqli->character_set_name();

debug $mysqli->character_set_name();

 

<?php$mysqli = new mysqli(‘localhost‘, ‘root‘, ‘‘, ‘w‘);if(mysqli_connect_errno()){    printf(‘Connect failed: %s\n‘, mysqli_connect_errno());    exit();}$charset = $mysqli->character_set_name(); //Initial character set //latin1//Sets the default character set to be used when sending data from and to the database server. BOOLif($charset !== ‘utf8‘) $mysqli->set_charset(‘utf8‘);$charset = $mysqli->character_set_name(); //Current character set //utf8

 

<?php$mysqli = new mysqli(‘localhost‘, ‘root‘, ‘‘, ‘w‘);if(mysqli_connect_errno()){    printf(‘Connect failed: %s\n‘, mysqli_connect_errno());    exit();}if(!$mysqli->set_charset(‘utf8‘))echo $mysqli->error;
if(!$mysqli->set_charset(‘2utf8‘))echo $mysqli->error; //Invalid characterset or character set not supportedif(!$mysqli->set_charset(‘utf-8‘))echo $mysqli->error; //Invalid characterset or character set not supportedif(!$mysqli->set_charset(‘UTF-8‘))echo $mysqli->error; //Invalid characterset or character set not supported

 

debug $mysqli->character_set_name();