我会尝试再次询问这个问题,但不会输入错误......我正在使用 MySQLi 进行连接,并故意使用错误的连接变量来触发错误。
按预期工作:
$conn = mysqli_connect("localhost","x","x","x");
if (mysqli_connect_errno()) {
echo "Couldn't establish database connection blah blah";
}
这应该完全相同,但它显示“无法获取 MySQLi”警告:
$conn = new mysqli("localhost","x","x","x");
if ($conn->connect_errno) {
echo "Couldn't establish database connection blah blah";
}
当连接细节良好时,这两种方法都很好,尽管这不是重点。