python72 Posted February 25, 2011 Share Posted February 25, 2011 I know mysql provides some trigger possibilities but I wonder if I could do something more with it. I would like to trigger command (php file) when certain values are set. Let say I am looking for certain values in my database to match predefined values which would trigger that file to run. I know I can have php file checking values in the database and if these values match to go on with the remainder of the execution or exit after the check if the values don't match but I think that doing it directly from database would be more efficient since I would have to have few cron jobs runned at intervals to make sure I eventually get all the values to match and can execute my action. Quote Link to comment https://forums.phpfreaks.com/topic/228830-mysql-trigger-question/ Share on other sites More sharing options...
mikosiko Posted February 26, 2011 Share Posted February 26, 2011 triggers doesn't work in a way that allow you to do what you are asking for... worth to read: http://dev.mysql.com/doc/refman/5.0/en/triggers.html and be sure to read this too: http://dev.mysql.com/doc/refman/5.0/en/stored-program-restrictions.html Quote Link to comment https://forums.phpfreaks.com/topic/228830-mysql-trigger-question/#findComment-1179864 Share on other sites More sharing options...
DavidAM Posted February 26, 2011 Share Posted February 26, 2011 Even if you could do this, it is not a good idea. During the execution of a trigger, the tables being affected are locked (at least the pages containing the rows being modified) and will remain locked until the trigger completes. If you started an external process, and that process hung up, the server could hang. If the process you started, tried to access the data that fired the trigger, it would not be able to because the data is locked. It will wait for the lock to be released, the lock will not be released until after the process is finished, and the process can't finish until the lock is released. This is called a "Livelock", the database server cannot tell that the process will never continue, so it is not a Deadlock. The process would hang until you killed it, which would likely cause the transaction to rollback and the data will NOT be updated. Triggers were invented to insure database integrity. They should not be used for application code. They must be fast and efficient code. A cron job is your best choice. A well written, efficient script will should not be a problem for the server. Quote Link to comment https://forums.phpfreaks.com/topic/228830-mysql-trigger-question/#findComment-1179884 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.