我的项目运作良好,但突然显示错误显示:
“在布尔值中调用成员函数set_charset() /home1/express/public_html/conn.php在第9行“
这是我的conn.php
<?php
$db_name = "";
$server_name = "";
$username = "";
$password = "";
// Create connection
$conn = mysqli_connect($server_name, $username, $password, $db_name);
$conn->set_charset("utf8"); `
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
?>
答案 0 :(得分:1)
在设置字符集
之前,您需要检查是否有mysqli对象更改此行
$conn = mysqli_connect($server_name, $username, $password, $db_name);
$conn->set_charset("utf8"); `
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
到
$conn = mysqli_connect($server_name, $username, $password, $db_name);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$conn->set_charset("utf8"); `