tags:

views:

26

answers:

1

I have two fields in my database that simply store on and off times for my application. I need to make sure that the off time is not greater than the on time. I believe that a trigger may be good but I have never written one before. Can someone either verify that a trigger is the way to go or maybe writing some PHP code to handle this would be better... Any suggestions or trigger snippets are welcome.

I'm storing the on off times which are the user's preferences. If I could get the database to return false or maybe through my PHP code, I could test for a return value and then handle it accordingly.

+1  A: 

since mysql does not seem to allow a smooth way to abort a trigger and raise an error with an error message I would look to put this logic in the PHP code. See http://www.brokenbuild.com/blog/2006/08/15/mysql-triggers-how-do-you-abort-an-insert-update-or-delete-with-a-trigger/

fupsduck
Thanks for the link fups. Maybe handling this through the database isn't the best way to go about it. I thought that I would be able to save some time coding PHP and let the db handle it.
Todd PA
+1: Beat me to it. I still think it is worth implementing the trigger, in order to stop anyone connecting to the table to change values.
OMG Ponies