Welcome Guest ( Log In | Register )




                Web Hosting

 
Reply to this topicNew Topic
In Php, How To Not Display Mysql Connection Error?, Don't want mysql_connect() message
jedipi
post Apr 4 2005, 12:58 PM
Post #1


Premium Member
Group Icon

Group: Members
Posts: 352
Joined: 2-March 05
From: Australia
Member No.: 2,859


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.
Go to the top of the page
 
+Quote Post
vujsa
post Apr 4 2005, 01:12 PM
Post #2


Absolute Newbie
Group Icon

Group: Admin
Posts: 888
Joined: 20-February 05
From: Indianapolis, Indiana, USA (Midwest)
Member No.: 2,714
myCENTs:35.43


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
Go to the top of the page
 
+Quote Post
vizskywalker
post Apr 4 2005, 06:07 PM
Post #3


Techno-Necromancer
Group Icon

Group: Members
Posts: 1,018
Joined: 13-January 05
From: The Net
Member No.: 2,127


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
}
Go to the top of the page
 
+Quote Post
jedipi
post Apr 5 2005, 02:04 AM
Post #4


Premium Member
Group Icon

Group: Members
Posts: 352
Joined: 2-March 05
From: Australia
Member No.: 2,859


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");
Go to the top of the page
 
+Quote Post
vizskywalker
post Apr 5 2005, 02:21 AM
Post #5


Techno-Necromancer
Group Icon

Group: Members
Posts: 1,018
Joined: 13-January 05
From: The Net
Member No.: 2,127


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.
Go to the top of the page
 
+Quote Post

Reply to this topicNew Topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   14 ikenalleenik 2,275 30th December 2008 - 01:22 PM
Last post by: iG-saumyadeep
No New Posts 3 FirefoxRocks 155 24th December 2008 - 01:43 PM
Last post by: Quatrux
No New Posts 6 terminal2k 196 15th December 2008 - 11:58 PM
Last post by: terminal2k
No New Posts   10 m3th 3,225 8th December 2008 - 09:08 PM
Last post by: iG-silv3r
No New Posts   8 nakulgupta 2,025 4th December 2008 - 05:26 AM
Last post by: iG-tohir
No New Posts   5 derouge 1,536 30th November 2008 - 07:16 AM
Last post by: iG-Rev.Keith Ratliff
No New Posts   2 magiccode9 164 17th November 2008 - 12:05 PM
Last post by: magiccode9
No New Posts   8 Running With Scissors 419 10th November 2008 - 10:05 PM
Last post by: Running With Scissors
No New Posts 4 borejk 480 5th November 2008 - 11:14 AM
Last post by: Guest
No New Posts   2 xboxrulz 232 3rd November 2008 - 12:00 AM
Last post by: xboxrulz
No New Posts   5 lonebyrd 1,553 29th October 2008 - 11:00 PM
Last post by: Guest
No New Posts   11 rckstr4lfe 3,617 26th October 2008 - 03:54 PM
Last post by: Guest
No New Posts 6 efrain_aguilar 719 24th October 2008 - 08:50 PM
Last post by: yordan
No New Posts   6 xboxrulz 211 23rd October 2008 - 06:44 PM
Last post by: xboxrulz
No New Posts   6 Gollum 1,287 13th October 2008 - 04:05 PM
Last post by: Mordent