0

Any solutions to run an action in MySQL when table is updated?

If so, how about taking values from the updated table and passing it to the script to run it?

alexel
  • 197
  • 1
  • 1
  • 11
  • its called a trigger:http://dev.mysql.com/doc/refman/5.7/en/create-trigger.html –  Feb 21 '16 at 23:27

2 Answers2

0

You can try with triggers, but if you realy need php you ned other solution.

Update a timestamp afer insert or update. And run a php script in cron task every x time to get the values For exampe every hour, get the values in sql like this timestamp >= now() -INTERVAL 1 HOUR

David
  • 1,116
  • 3
  • 18
  • 32
0

As Dagon said in the comment, you are looking for a trigger. http://dev.mysql.com/doc/refman/5.7/en/create-trigger.html

BUT: You can not execute PHP code, you can only SQL Statements, for example updating another table, etc.

A "slow" solution could be, that a trigger sets some flag value in DB and a cron job PHP-script executes every minute (or something like that) and checking this flag. When it is set, the fetch new data and do whatever you want to do and reset the flag.

Or: Invoking a PHP script from a MySQL trigger

Community
  • 1
  • 1
Fabian N.
  • 1,221
  • 10
  • 18