bookmark - In Php, How To Not Display Mysql Connection Error? Don't want mysql_connect() message

In Php, How To Not Display Mysql Connection Error? - Don't want mysql_connect() message

 
 Discussion by jedipi with 4 Replies.
 Last Update: April 5, 2005, 2:21 am
 
bookmark - In Php, How To Not Display Mysql Connection Error? Don't want mysql_connect() message  
    
free web hosting
 
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.

Mon Apr 4, 2005    Reply    New Discussion   


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

Mon Apr 4, 2005    Reply    New Discussion   

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:

CODE

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

Mon Apr 4, 2005    Reply    New Discussion   

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

Tue Apr 5, 2005    Reply    New Discussion   


That'll do it. Whenever you need to debug a script, remember the die() function. Most scripting languages have it and it is very useful.

Tue Apr 5, 2005    Reply    New Discussion   

Quickly Post to In Php, How To Not Display Mysql Connection Error? Don't want mysql_connect() message w/o signup Share Info about In Php, How To Not Display Mysql Connection Error? Don't want mysql_connect() message using Facebook, Twitter etc. email your friend about In Php, How To Not Display Mysql Connection Error? Don't want mysql_connect() message Print
Reply / Comment Ask a Question? Share / Bookmark E-Mail a Friend Print

I Need Some Help On Php php developers help  I Need Some Help On Php php developers help (7) (10) Beginners Php - Object Initialization   Beginners Php - Object Initialization