Mysqli_set_charset

Mysqli_set_charset utf8
  1. Php Mysqli_set_charset

Syntax bool mysqlisetcharset (mysqli $link, string $charset). I'm setting up a new server and want to support UTF-8 fully in my web application. I have tried this in the past on existing servers and always seem to end up having to fall back to ISO-8859-1.

Mysqli::setcharset mysqlisetcharset (PHP 5 = 5.0.5, PHP 7) mysqli::setcharset- mysqlisetcharset — Establece el conjunto de caracteres predeterminado del cliente. 很多新手朋友学习PHP的时候,发现程序中的中文在输出的时候会出现乱码的问题,那么为什么会出现这种乱码的情况呢?一般来说,乱码的出现有2种原因,一种是由于编码(charset) 设置错误,导致浏览器以错误的编码来解析,从而出现了满屏乱七八糟的“天书”,第二种就是文件被以错误的编码打开.

Php Mysqli_set_charset

<?php
$mysqli
= new mysqli('localhost', 'my_user', 'my_password', 'test');
/* check connection */
if (mysqli_connect_errno()) {
printf('Connect failed: %sn', mysqli_connect_error());
exit();
}
printf('Initial character set: %sn', $mysqli->character_set_name());
/* change character set to utf8mb4 */
if (!$mysqli->set_charset('utf8mb4')) {
printf('Error loading character set utf8mb4: %sn', $mysqli->error);
exit();
} else {
printf('Current character set: %sn', $mysqli->character_set_name());
}
$mysqli->close();
?>