在boolean上调用成员函数set_charset()

时间:2017-05-02 02:36:53

标签: php html mysql

$dbhost = ($_SERVER['HTTP_HOST'] == "localhost") ? 'localhost' : 'localhost';
$dbuser = ($_SERVER['HTTP_HOST'] == "localhost") ? 'ppapcom_ppap' : 'ppapcom_ppap'; //'trs-camb_admin';
$dbpwd = ($_SERVER['HTTP_HOST'] == "localhost") ? 'it@a2z' : 'it@a2z';
$dbname = ($_SERVER['HTTP_HOST'] == "localhost") ? 'ppapcom_ppapadmin' : 'ppapcom_ppapadmin'; //'trs-camb_motdb';
$conn = mysqli_connect('localhost', $dbuser, $dbpwd, $dbname); 
$conn -> set_charset("utf8");
if (!$conn) { 
    die('Could not connect to MySQL: ' . mysqli_error($conn)); 
}

1 个答案:

答案 0 :(得分:0)

您与数据库的连接失败,您可以使用:

if ($conn->connect_error) {
    die('The error was: ' . $conn->connect_error);
}

要确定错误是什么,请在set_charset()调用之前放置它。