Loading...


bookmark - Suppressing Mysql Error In Php How to suppress auto generated mysql err

Suppressing Mysql Error In Php - How to suppress auto generated mysql err

 
 Discussion by kvkv with 4 Replies.
 Last Update: February 2, 2006, 9:41 am
 
bookmark - Suppressing Mysql Error In Php How to suppress auto generated mysql err  
Quickly Post to Suppressing Mysql Error In Php How to suppress auto generated mysql err w/o signup Share Info about Suppressing Mysql Error In Php How to suppress auto generated mysql err using Facebook, Twitter etc. email your friend about Suppressing Mysql Error In Php How to suppress auto generated mysql err Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

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?








   Wed Feb 1, 2006    Reply         

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.

   Wed Feb 1, 2006    Reply         

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;
}
?>

   Thu Feb 2, 2006    Reply         


QUOTE (adly3000)

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!

   Thu Feb 2, 2006    Reply         

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.

   Thu Feb 2, 2006    Reply         

Quickly Post to Suppressing Mysql Error In Php How to suppress auto generated mysql err w/o signup Share Info about Suppressing Mysql Error In Php How to suppress auto generated mysql err using Facebook, Twitter etc. email your friend about Suppressing Mysql Error In Php How to suppress auto generated mysql err Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

Similar Topics:

Mysql Php Apache Downloads And Se...

Mysql, PHP, Apache downloads were easy enough. Then came the setup process. This seemed to be an endless mess of going back and forth trying to get the programs to work together properly. Finaly I got them working after about 48 hours. There are great tutorials on the setup process, but only one or ...more

   20-Apr-2008    Reply         

Php And Mysql Programming

hi everyone! I am making a program using php and mysql...I am a noob on this so i need your help guys...I want to make a simple program that will some values and then store them on a database and then retrieve them...uhmm let me give an example out put of what i need. T ...more

   05-May-2008    Reply         

Best Php And Mysql Editor For Noobs

hi there guys, from my previous posting, i am a noob in php and mysql programming. I want to know if there are any php and mysql editors which are best for me as a noob. i appreciate your kindness ...more

   06-May-2008    Reply         

Study Php With Phpflashcards phpflashcards.com   Study Php With Phpflashcards phpflashcards.com (1) (2) Crontab Automated Database Backup using crontab to make automated database  Crontab Automated Database Backup using crontab to make automated database