Welcome Guest ( Log In | Register )



 
Reply to this topicStart new 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 topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Need Help With A PHP - MySQL Registration Script(13)
  2. [PHP + MySQL] Encrypting Data(11)
  3. Important: Basics Of Using PHP And MySQL(10)
  4. E-mail List Error(4)
  5. Got A Wee Error - Can You Help?(13)
  6. Need MySQL Alternative To The Syntax "or die()"(8)
  7. Re-order MySQL Table(11)
  8. PHP & MySQL: Displaying Content From A Given ID(6)
  9. How To Show Serial Nums In PHP Table For Contents Of MySQL DB(4)
  10. Error On Submit Page(10)
  11. Php Mysql Errors(2)
  12. Sql Injection Prevention (passing Numerical Data Across Pages).(9)
  13. Php/mysql And Manual Page Caching?(4)
  14. Too Many Connections?(4)
  15. Extracting Mysql Maths Using Php(2)
  1. Unexpected Error(2)
  2. Php Math Error(4)
  3. Anyone Know Of A Really Good Mysql Class?(4)
  4. Warning: Mysql_num_rows()(1)
  5. Warning: Mysql_result(): Supplied Argument Is Not A Valid Mysql Result Resource In ...(4)
  6. How To Make A PM (Personal Message) System?(5)
  7. Php Error-where To Put "?>"(2)
  8. Making A Link = Mysql_query(8)
  9. Making Something In Mysql Happen Only Once(10)
  10. Mysql Question(inserting Number From A Textfield)(3)
  11. Letting Users Add Mysql Data With Php(1)
  12. Cant Find The Error(2)
  13. Php Configuration Error?(6)


 



- Lo-Fi Version Time is now: 22nd November 2008 - 02:37 PM