-2

I have a stored procedure, a controller and a model.

Where should I do the database error checking[No rows returns, table has conflicting primary key, invalid values specified, etc?] in my procedure or model? and from where should I be displaying messages out to the user[ Update successful, Could not execute statement, etc ]?

What is the better practice?

Undermine2k
  • 1,481
  • 4
  • 28
  • 52
  • read this http://www.roseindia.net/tutorial/java/jdbc/javamvcdesignpattern.html – Pradeep Gamage Aug 30 '12 at 05:07
  • stored procedure is not a view, and since you don't provide more details about your controller and a model - the answers you'll get will be very limited. Also, it sounds like it has nothing to do with MVC, I would change the question to simply: "where should be the error checking of a stored procedure". – Nir Alfasi Aug 30 '12 at 05:21

3 Answers3

4

The error checking should happen in the model layer.

To be specific, in data mappers or other structures which deal with data abstraction. If you are using PDO, an SQL error would rise an exception, which is handles at the level of storage abstractions. This is done by assigning an error state to the domain object, which you were storing or populating at that time.

Controller exists in completely different layer: presentation layer. It should not be aware of internal problems of domain business logic, which is handles by model layer. That would lead to a leaking abstraction.

The view, when gathering information to display, should at first request the services, that it uses, to return the status. If services inform the view about existing error state, view request more detailed information, and decides how to react this the error and which group templates to utilized for visualization of the error state.

Community
  • 1
  • 1
tereško
  • 58,060
  • 25
  • 98
  • 150
1

Yes, all the error messages and display items should be handled in View where as the database error checkings can be done in model.

srinath
  • 2,748
  • 6
  • 35
  • 56
  • 2
    No, you may choose to *display* error messages in the `view`, but errors should not be handled by it. Data (and error) handling should be done by the `model`. – Nir Alfasi Aug 30 '12 at 05:26
0

In my opinion DB error checking should go into the model, displaying (everything) is going to the "view" layer. You can find a nice post about making an MVC framework here:

http://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/

ragklaat
  • 926
  • 5
  • 12