简体   繁体   English

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

[英]MySQL error message along with PHP error message

<?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);
?>

We have this in setup this in our localhost. 我们在本地主机中对此进行设置。 When there no connection with the database we get the error along with the error message. 当与数据库没有连接时,我们会收到错误以及错误消息。

Warning : mysql_connect(): No connection could be made because the target machine actively refused it. 警告 :mysql_connect():由于目标计算机主动拒绝连接,因此无法建立连接。 in D:\\core\\database\\connect.php on line 3 在第3行的D:\\ core \\ database \\ connect.php中
Sorry We could not able to connect to the database 抱歉,我们无法连接到数据库

How to show only the message and not the default sql error. 如何仅显示消息而不显示默认的SQL错误。

Thanks! 谢谢!

First: Don't use mysql_* -methods anymore , they're deprecated. 首先: 不再使用mysql_*方法 ,不推荐使用。 Instead use mysqli or PDO. 而是使用mysqli或PDO。

For your error, disabling the error-reporting according to this documentation should help. 对于您的错误,根据本文档禁用错误报告应该会有所帮助。

Just add error_reporting(0); 只需添加error_reporting(0); to the beginning of your file. 到文件的开头。

Hey default errors are caused due to php itself, you can turn them off in the php configuration file and you have to turn them off really because watching errors give an attacker knowledge of how your site works and your sites internal structure. 嘿,默认错误是由php本身引起的,您可以在php配置文件中将其关闭,而您实际上必须将其关闭,因为观看错误可以使攻击者了解您的网站的工作方式和网站的内部结构。 So just turn off the error_reporting in php configuration 因此,只需turn off the error_reporting in php configuration

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM