|
|
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 | |||
![]() |
|
|
Can I suppress this message and display only my message?
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.
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;
}
?>
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!
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:
Mysql Php Apache Downloads And Se...
Php And Mysql Programming
Best Php And Mysql Editor For Noobs
Study Php With Phpflashcards phpflashcards.com (1)
|
(2) Crontab Automated Database Backup using crontab to make automated database
|
Loading...
HOME 






