0
<?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!

Dexter
  • 7,911
  • 4
  • 41
  • 40
  • Possible duplicate of [mysql\_connect(): No connection could be made because the target machine actively refused it](http://stackoverflow.com/questions/21987746/mysql-connect-no-connection-could-be-made-because-the-target-machine-actively) – e4c5 Aug 12 '16 at 07:17

2 Answers2

1

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.

UeliDeSchwert
  • 1,146
  • 10
  • 23
0

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

StackB00m
  • 502
  • 1
  • 5
  • 16
  • Thanks! I keep it open because we need to see other errors. By turning off, other errors won't show up right. – Dexter Aug 12 '16 at 07:19
  • yes if you turn off other erros wont show! you can do one thing for sure, while testing you code you can keep it on, but while implementing it on server and giving it to users please turn off ! – StackB00m Aug 12 '16 at 07:20
  • Wait.. your solution is to turn errors off instead of handle them? And this guy even listens to you? Ever heard of `@` in php? – N.B. Aug 12 '16 at 07:57
  • so you are suggesting he goes and keeps @ at all the statements that cause errors lol; i am suggesting using `try catch blogs to handle errors` you are suggesting using @ at all the errors! what if you couldnt find all the error statements because you are giving well inputs, but when some user gives unvalid inputs and see's ur sites error message exposing your sites internal structure lol – StackB00m Aug 12 '16 at 08:08