Dexter
Dexter

Reputation: 9324

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. in D:\core\database\connect.php on line 3
Sorry We could not able to connect to the database

How to show only the message and not the default sql error.

Thanks!

Upvotes: 0

Views: 107

Answers (2)

UeliDeSchwert
UeliDeSchwert

Reputation: 1156

First: Don't use mysql_*-methods anymore, they're deprecated. Instead use mysqli or PDO.

For your error, disabling the error-reporting according to this documentation should help.

Just add error_reporting(0); to the beginning of your file.

Upvotes: 1

StackB00m
StackB00m

Reputation: 502

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. So just turn off the error_reporting in php configuration

Upvotes: 0

Related Questions