Jump to content
xisto Community
Sign in to follow this  
jedipi

In Php, How To Not Display Mysql Connection Error? Dont want mysql_connect() message

Recommended Posts

In PHP, if the mysql database server cannot be connected, for example database server is handed or turned off, an error message will be displayed:Warning: mysql_connect(): Unknown MySQL Server Host "mysql.example.com" ...My question is how to not display this warning message?or can I customise the error message?if so, how?Thank you.

Share this post


Link to post
Share on other sites

This should suppress most messages. Unless there is a die() message coded in and there probably is.@mysql_connect():Look for mysql_connect();and change to:@mysql_connect() or die("Sorry Server Error");however, you may want to investigate why you are getting an error message.Hope this helps!vujsa

Share this post


Link to post
Share on other sites

PHP also provides a mysql function to determine the error. The function is as follows: mysql_error(). It takes no parameters. If you want to use this information, you can either store it to a file or display it on the webpage. Follow this code:

$variable = mysql_connect(); //This assigns the connetion to $variable, on failure $variable is null and there is no error messageif (!$variable){ //If variable doesn't exist, there was a failure//code to either display the error or save it to a filedie(); //end the script}

Share this post


Link to post
Share on other sites

Problem fixed...thank you so much.here is my statement:$db_link = @mysql_connect($db_host,$db_username,$db_password) or die("Cann't Connect to Database.\n");

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.