DISQUS

Code Spatter: How To Use Triggers to Track Changes in MySQL

  • Greg Allard · 1 year ago
    Someone posted this on a link sharing site and there has been some discussion going on there. http://news.ycombinator.com/item?id=182529
  • Dhiraj Das · 1 year ago
    Really help full. But, this is the way to execute multiple query using sqli, but what about mysql
  • Greg Allard · 1 year ago
    php's mysql improved function is the only way I have tested doing multiple queries like this in a php script. Some PEAR libraries might be able to help also. Are you in a situation where you can't use mysqli?
  • mysqlearner · 1 year ago
    hi ,
    please can u explain what is
    OLD.first_name != NEW.first_name
    are they table names?
    I need to write atrigger to get the changed row and also how do i get the same query either insert,update or delete.
    thanks in advance
  • Greg Allard · 1 year ago
    OLD and NEW are used on UPDATE triggers. OLD.col_names will access the data that is in the row of the database before the UPDATE query runs and NEW.col_names will access the data that the row will be updated to.

    IF OLD.first_name != NEW.first_name

    That checks if the UPDATE query is changing the information for first_name.
  • Sean · 8 months ago
    Does any way work as trigger in mysql 4.1? I know that triggers is supported from mysql 5.0
    thanks for help
  • Greg Allard · 8 months ago
    I don't think there is anyway to do it in the database, but you can still put the logic in your application. If you are using django, there are signals that will help get that done. http://docs.djangoproject.com/en/1.0/topics/sig... If you aren't then you will need to program it into your project in some other way.
  • abhinavzone · 5 months ago
    Thank you very much!!! it saved my day
  • Phani Kumar Varanasi · 1 month ago
    Yeah Dear, the concept you entered is so helpful, well good work.