|
|
|
|
![]() ![]() |
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.
|
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 22nd November 2008 - 02:37 PM |