0
Warning: mysqli_connect(): (HY000/2002): No connection could be made because the target     machine actively refused it. in E:\xampp\htdocs\ss\docs\regional.php on line 15
The connection to the database could not be established.

这是一个严重的错误还是很容易被忽略?错误消息'The connection to the database could not be established.'expected to pop但是not the warning text。在这种情况下如何删除它。下面是我使用的代码。

$db = mysqli_connect('localhost', 'root', '', 'regional_data');
if(mysqli_connect_errno()) {die('The connection to the database could not be established.');}

编辑:我已经在开发区域停止了 SQL 来测试这个并且当时出现了消息。

4

3 回答 3

1

在您的开发环境中,打开 display_errors 的设置是完全合法的。这是查看事情是否出错的最简单方法。

在生产环境中,您不会将其设置为 on,因为用户通常不需要知道 PHP 是否出错 - 他甚至不应该知道,因为这些消息可能包含对攻击者有价值的信息。那只能通过专用的错误消息来传达,例如在您的内部die()

因此,如果您禁用 display_errors,输出中的警告将消失,但您确实希望在日志文件中包含此警告。不建议使用 an 来抑制警告@

于 2012-10-19T18:07:52.663 回答
0

由于您拥有error_reportingdisplay_errors设置的方式,可能只会在您的开发环境中显示警告。

错误报告

ini_set('display_errors', 0)

编辑:澄清一下,如果您的 error_reporting 级别在您的开发环境中包含警告,它们可以包含在显示到屏幕的错误中。要进行测试,请设置displays_errors为 0,如上所述,在 mysqli 连接之前。

于 2012-10-19T18:05:30.867 回答
-1

您可以通过调用以 开头的函数来抑制警告@,但最好确保修复错误的来源。

例如$db = @mysqli_connect(...)

于 2012-10-19T18:04:27.377 回答