Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Suppressing Mysql Error In Php, How to suppress auto generated mysql err
kvkv
post 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?
Go to the top of the page
 
+Quote Post
jlhaslip
post 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 Icon

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
Spam Patrol



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.
Go to the top of the page
 
+Quote Post
adly3000
post 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;
}
?>
Go to the top of the page
 
+Quote Post
kvkv
post 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!
Go to the top of the page
 
+Quote Post
Spectre
post 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.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Problem On Mysql "order By"(5)
  2. Php News Script(19)
  3. Trouble With Emailer.php(6)
  4. Increment A Mysql Column(7)
  5. Can Reset The Id Auto Increment?(11)
  6. Parse: Error Unexpected T_lnumber(4)
  7. Can You Add Images Into A Mysql Database?(20)
  8. Subquery In Mysql(5)
  9. Creating Profiles In Php/mysql ?(7)
  10. Php Search Engine Script For Mysql Database(11)
  11. Some Mysql Basics(4)
  12. The Artists Tutorials :mysql Basic Commands(0)
  13. T_string Error Please Assist(5)
  14. Delete Problem With Id(4)
  15. [mysql]get Id Of Loged In User?(7)
  1. [mysql/php]need Som Basic Help(13)
  2. [php/mysql]id Trouble [resolved](3)
  3. Mysql Won't Update(4)
  4. Php + Mysql Question!(4)
  5. Php Objects: Catchable Fatal Error(4)
  6. Tools Needed!(9)
  7. Best Sites For Learning Php-mysql(4)
  8. Php And Mysql Programming(2)
  9. Best Php And Mysql Editor For Noobs(6)
  10. Html Form!(4)
  11. Mysql Error(3)
  12. Create Table - Mysql Code - Help(1)
  13. Linux/ Apache /mod_rewrite Issue(4)


 



- Lo-Fi Version Time is now: 12th October 2008 - 02:20 PM