Disable "die" message

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
50CENT
Forum Newbie
Posts: 2
Joined: Tue Jan 15, 2008 10:31 am

Disable "die" message

Post 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.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Disable "die" message

Post by Kieran Huggins »

change the error reporting level: http://php.net/error-reporting
50CENT
Forum Newbie
Posts: 2
Joined: Tue Jan 15, 2008 10:31 am

Re: Disable "die" message

Post by 50CENT »

Thank you it works perfectly now !!

Cheers,
50.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Disable "die" message

Post by Kieran Huggins »

np

wouldn't that be .50?
User avatar
jimthunderbird
Forum Contributor
Posts: 147
Joined: Tue Jul 04, 2006 3:59 am
Location: San Francisco, CA

Re: Disable "die" message

Post by jimthunderbird »

Will the following code has the same effect?

Code: Select all

 
$rs4 = mssql_query($query4) 
if(!rs4){
  echo "TRANSACTION MUST BE UNIQUE";
}
 
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Disable "die" message

Post 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).
Post Reply