创建错误后无法显示错误消息
我正在尝试使用Localhost连接到数据库。
<?php
//Connecting to the Database
$servername = "localhost";
$username = "root";
$password = "";
// Create a connection
$conn = mysqli_connect($servername, $username, $password);
// Die if connection was not successful
if (!$conn){
die("Sorry we failed to connect: ". mysqli_connect_error());
}
else{
echo "Connection was successful";
}
?>
如果建立连接,它可以工作,但我不明白 当我故意创建错误时,“对不起,我们无法连接”消息。
这可能是什么原因?
I'm trying to connect to the database using localhost.
<?php
//Connecting to the Database
$servername = "localhost";
$username = "root";
$password = "";
// Create a connection
$conn = mysqli_connect($servername, $username, $password);
// Die if connection was not successful
if (!$conn){
die("Sorry we failed to connect: ". mysqli_connect_error());
}
else{
echo "Connection was successful";
}
?>
It works if the connection is made but I don't get the
"Sorry we failed to connect" message when I intentionally create an error.
What could be the potential causes of this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如 documentation ::
由于您有例外,因此必须设置此设置。在这种情况下,您的代码应如下更改:
As stated in the documentation:
Since you are getting an exception, this must be set. Your code should change as follows in this case: