Page 1 of 1

Disable "die" message

Posted: Tue Jan 15, 2008 10:39 am
by 50CENT
Hi everybody,

I have a pretty dumb question for you guys about how to disable the "die" message if a query fails.

I am using PHP5 with an MS-SQL Database.

example:

If a query fails, I want to show only something like:

"TRANSACTION MUST BE UNIQUE"

rather than

"Warning: mssql_query() [function.mssql-query]: message: Violation of UNIQUE KEY constraint 'myNewContraint'. Cannot insert duplicate key in object 'myTransactions'. (severity 14) in C:\myPage.php on line 111

Warning: mssql_query() [function.mssql-query]: Query failed in C:\myPage.php on line 111"

I am using this code:

Code: Select all

 
$rs4 = mssql_query($query4) or die('TRANSACTION MUST BE UNIQUE');
 
But it shows both messages.

Thank you for your help.

Re: Disable "die" message

Posted: Tue Jan 15, 2008 10:53 am
by Kieran Huggins
change the error reporting level: http://php.net/error-reporting

Re: Disable "die" message

Posted: Tue Jan 15, 2008 11:22 am
by 50CENT
Thank you it works perfectly now !!

Cheers,
50.

Re: Disable "die" message

Posted: Tue Jan 15, 2008 11:32 am
by Kieran Huggins
np

wouldn't that be .50?

Re: Disable "die" message

Posted: Tue Jan 15, 2008 11:40 am
by jimthunderbird
Will the following code has the same effect?

Code: Select all

 
$rs4 = mssql_query($query4) 
if(!rs4){
  echo "TRANSACTION MUST BE UNIQUE";
}
 

Re: Disable "die" message

Posted: Tue Jan 15, 2008 1:25 pm
by RobertGonzalez
No, the error message he was getting came from the PHP engine. It was displaying errors and had error_reporting set to E_ALL (or at least enough to show warnings).