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!

1

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Its PDO not DBO. Update it
Darn, war wrong in my memories. Thanks for pointing this out @Tamil
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

4 Comments

Thanks! I keep it open because we need to see other errors. By turning off, other errors won't show up right.
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 !
Wait.. your solution is to turn errors off instead of handle them? And this guy even listens to you? Ever heard of @ in php?
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.