<?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. BOOL
if($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 supported
if(!$mysqli->set_charset('utf-8'))echo $mysqli->error; //Invalid characterset or character set not supported
if(!$mysqli->set_charset('UTF-8'))echo $mysqli->error; //Invalid characterset or character set not supported