-3

Is there anyway to make a listener for any update happens in database (mysql) using php? for example. if you make any update in database (change an entry or element) it will notify you or make a specific function.

  • 3
    http://stackoverflow.com/questions/1467369/invoking-a-php-script-from-a-mysql-trigger – Timurib Nov 18 '16 at 08:36
  • Welcome to Stack Overflow! To give you a great answer, it might help us if you have a glance at [ask] if you haven't already. It might be also useful if you could provide a [mcve]. – Mat Nov 18 '16 at 09:00

1 Answers1

0

It would be easier to use SQL triggers directly. Beside that PHP got it 's own classes in the SPL for event driven functionality.

Trigger example with SQL (taken from the examples from the link above)

mysql> CREATE TABLE account (acct_num INT, amount DECIMAL(10,2));
mysql> CREATE TRIGGER ins_sum BEFORE INSERT ON account
    -> FOR EACH ROW SET @sum = @sum + NEW.amount;

mysql> SET @sum = 0;
mysql> INSERT INTO account VALUES(137,14.98),(141,1937.50),(97,-100.00);
mysql> SELECT @sum AS 'Total amount inserted';

This example creates a trigger called ins_sum which calculates the sum of the inserted values after an insert statement is executed. After an insert statement you can select the @sum variable by a simple select statement.

Marcel
  • 4,854
  • 1
  • 14
  • 24