|
|
|
| Web Hosting |
![]() ![]() |
In Php, How To Not Display Mysql Connection Error?, Don't want mysql_connect() message |
Apr 4 2005, 12:58 PM
Post
#1
|
|
|
Premium Member 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. |
|
|
|
Apr 4 2005, 01:12 PM
Post
#2
|
|
|
Absolute Newbie 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 |
|
|
|
Apr 4 2005, 06:07 PM
Post
#3
|
|
|
Techno-Necromancer 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 } |
|
|
|
Apr 5 2005, 02:04 AM
Post
#4
|
|
|
Premium Member 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"); |
|
|
|
Apr 5 2005, 02:21 AM
Post
#5
|
|
|
Techno-Necromancer 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.
|
|
|
|
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
14 | ikenalleenik | 2,275 | 30th December 2008 - 01:22 PM Last post by: iG-saumyadeep |
|||
![]() |
3 | FirefoxRocks | 155 | 24th December 2008 - 01:43 PM Last post by: Quatrux |
|||
![]() |
6 | terminal2k | 196 | 15th December 2008 - 11:58 PM Last post by: terminal2k |
|||
![]() |
10 | m3th | 3,225 | 8th December 2008 - 09:08 PM Last post by: iG-silv3r |
|||
![]() |
8 | nakulgupta | 2,025 | 4th December 2008 - 05:26 AM Last post by: iG-tohir |
|||
![]() |
5 | derouge | 1,536 | 30th November 2008 - 07:16 AM Last post by: iG-Rev.Keith Ratliff |
|||
![]() |
2 | magiccode9 | 164 | 17th November 2008 - 12:05 PM Last post by: magiccode9 |
|||
![]() |
8 | Running With Scissors | 419 | 10th November 2008 - 10:05 PM Last post by: Running With Scissors |
|||
![]() |
4 | borejk | 480 | 5th November 2008 - 11:14 AM Last post by: Guest |
|||
![]() |
2 | xboxrulz | 232 | 3rd November 2008 - 12:00 AM Last post by: xboxrulz |
|||
![]() |
5 | lonebyrd | 1,553 | 29th October 2008 - 11:00 PM Last post by: Guest |
|||
![]() |
11 | rckstr4lfe | 3,617 | 26th October 2008 - 03:54 PM Last post by: Guest |
|||
![]() |
6 | efrain_aguilar | 719 | 24th October 2008 - 08:50 PM Last post by: yordan |
|||
![]() |
6 | xboxrulz | 211 | 23rd October 2008 - 06:44 PM Last post by: xboxrulz |
|||
![]() |
6 | Gollum | 1,287 | 13th October 2008 - 04:05 PM Last post by: Mordent |
|||
|
Lo-Fi Version | Time is now: 8th January 2009 - 12:21 AM |
© 2009 AstaHost: Free Web Hosting & Technical Discussion, Free Web Hosting. a member of xisto.
Powered by Invision Board. Skin: IPB Forum Skins
Expand / Collapse Navigation



Apr 4 2005, 12:58 PM




