1

I have a PHP application on top of an Oracle DB. In the database, there are some constraints defined. When they get violated, I get a plain constraint violated message. I would like to have some custom message shown to the user.

Is there a way to define in the definition of the constraint a custom error message ? Or how would you suggest me to approach this issue ?

Thanks!

Tchypp
  • 1,075
  • 2
  • 13
  • 20
  • I don't want to. The question needs to remain generic. Although, I can give an example. Let's say I want to insert a new entry in my Student table. For several columns I have constraints defined, like name has to be not null, surname has to be not null, age must be positive, and so on. When I insert my new student, one of the constraints may get violated and I get an error message that is not very user friendly. This is why I would like to define an error message within each constraint that I would receive when it gets violated. To be able to show it to the user such that he understands it. – Tchypp Oct 10 '11 at 07:58
  • 2
    See http://stackoverflow.com/questions/6068792/is-there-way-to-give-user-friendly-error-message-on-constraint-violation – Tony Andrews Oct 10 '11 at 15:16

2 Answers2

0

Catch the exception and inform the user however you feel is appropriate.

php: catch exception and continue execution, is it possible?

Community
  • 1
  • 1
Marvo
  • 17,845
  • 8
  • 50
  • 74
0

Ask yourself why your invalid data is reaching your database?

You should implement strong validation on your inputs to prevent this happening as the constraints are only there as a last resort, not a front line for validating data.

Create validation routines that trap and report back (with a useful message) invalid data only sending valid data to be inserted into your database.

This could be done using PL/SQL stored procedures/packages/functions, a good article on using them for CRUD operations is here: http://www.devshed.com/c/a/Oracle/Developing-Simple-PL-SQL-Stored-Procedures-for-CRUD-Operations/

Or you could potentially use database triggers for this purpose, though "BEFORE" operation triggers are not as efficient as bulk processing collection data in a PL/SQL validation package.

Hope this helps...

Ollie
  • 17,058
  • 7
  • 48
  • 59