|
|
|
|
![]() ![]() |
Feb 1 2006, 10:43 PM
Post
#1
|
|
|
Newbie [Level 3] ![]() ![]() ![]() Group: Members Posts: 40 Joined: 29-January 06 Member No.: 17,841 |
I am testing my website on my local machine. It is still in development stage and I am using php/mysql. If there is a mysql connection error, I am checking for the connection variable and displaying a proper error message. But even before it displays my error message, it displays an error message on browser thrown by mysql (MySQL Connection Failed: Access denied for user).
Can I suppress this message and display only my message? |
|
|
|
Feb 1 2006, 11:41 PM
Post
#2
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 4,081 Joined: 24-July 05 From: Linix, DOS and Windows…the good, the bad and the ugly Member No.: 9,787 ![]() |
From the php.net site, we have this function:
CODE <?php // Turn off all error reporting error_reporting(0); ?> found here. http://ca3.php.net/error_reporting And I think that there is a way to use the '@' symbol in front of the function, but I couldn't source a link. Maybe someone else has a link for that. But suppressing the errors won't make the logic or processes work any differently. It is best to find out what is causing the error in the first place. Since you are 'developing' the program, I would leave the full error reporting "ON" until the bugs are under control. Clearly, you want to know at this stage if anything is going wrong and fix it before implementing the code into the production environment. And using the '@' Error suppression on a function is not reccomended at the development stage, either, for the same reasons. If you are unable to connect, you want to know why that is the case and find the solution using the error reporting output. |
|
|
|
Feb 2 2006, 12:31 AM
Post
#3
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 58 Joined: 31-January 06 Member No.: 17,937 |
i think this may help you:
CODE <? $hostname = "localhost"; $database = "yourdatase"; $username = "user"; $password = "pass"; @ $conn = mysql_pconnect($hostname, $username, $password); if(!$conn) { echo "ERROR: Cannot connect to database. Please try again later!"; exit; } //select the database $db = mysql_select_db($database); if(!$db) { echo "ERROR: Cannot select database. Please try again later!"; exit; } ?> |
|
|
|
Feb 2 2006, 04:51 AM
Post
#4
|
|
|
Newbie [Level 3] ![]() ![]() ![]() Group: Members Posts: 40 Joined: 29-January 06 Member No.: 17,841 |
QUOTE(adly3000 @ Feb 1 2006, 07:31 PM) i think this may help you: CODE <? $hostname = "localhost"; $database = "yourdatase"; $username = "user"; $password = "pass"; @ $conn = mysql_pconnect($hostname, $username, $password); if(!$conn) { echo "ERROR: Cannot connect to database. Please try again later!"; exit; } //select the database $db = mysql_select_db($database); if(!$db) { echo "ERROR: Cannot select database. Please try again later!"; exit; } ?> That is what I was doing exactly. But still it was printing standard error as well as my error. I had to set error_reporting level as jlhaslip suggested. Thanks! |
|
|
|
Feb 2 2006, 09:41 AM
Post
#5
|
|
|
Privileged Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 873 Joined: 30-July 04 Member No.: 246 |
Provided the function being called does not explicitly send any output (ie. not as an error), prefixing it with an '@' symbol causes any errors to be supressed for that single instance only.
For example: CODE echo file_get_contents('non_existant_file'); Will, provided error_reporting is turned on, output an error about how PHP could not find the file specified. However: CODE echo @file_get_contents('non_existant_file'); Will prevent any error from being displayed (even though the error itself does actually occur). Instead of: CODE @ $conn = mysql_pconnect($hostname, $username, $password); Try: CODE $conn = @mysql_pconnect($hostname, $username, $password); Hope that makes sense. |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 12th October 2008 - 02:20 PM |