Send database mail

Viewed 62

I created a trigger in our web application to identify the cause. Whenever data will be changed according to mentioned SQL in trigger code, I keep old data in our database as a separate table but I want to send real-time notification as well. Is any way to send mail or something else for real-time notification when the trigger called?

I'm using MariaDB Server + PHP

1 Answers

I recommend do not do this in a trigger in the database. The reason is that a trigger executes before the transaction is committed. If a client receives the notification, and then looks for the data, they might not see any data, because it has not been committed yet.

Or the notification may be sent, but after that the transaction rolls back. So they will never see the change that caused the notification.

It's safer to do this in your application:

  1. Commit a change to the database.
  2. Send a notification after the application confirms the commit is successful.
Related