gpt4 book ai didi

php - MySQL 错误消息以及 PHP 错误消息

转载 作者:行者123 更新时间:2023-11-29 11:21:08 26 4
gpt4 key购买 nike

<?php
//database connectivity
$connect_error='Sorry We could not able to connect to the database';
mysql_connect('localhost','root','') or die($connect_error);
mysql_select_db('beehive_intwebpage') or die ($connect_error);
?>

我们在本地主机中设置了这个。当没有与数据库连接时,我们会收到错误以及错误消息。

Warning: mysql_connect(): No connection could be made because the target machine actively refused it. in D:\core\database\connect.php on line 3
Sorry We could not able to connect to the database

如何仅显示消息而不显示默认的 sql 错误。

谢谢!

最佳答案

第一:不要再使用mysql_*-方法,它们已被弃用。请改用 mysqli 或 PDO。

对于您的错误,请根据 this documentation 禁用错误报告应该有帮助。

只需将 error_reporting(0); 添加到文件的开头即可。

关于php - MySQL 错误消息以及 PHP 错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38911918/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com