Question

Given an AFTER INSERT trigger on a mysql database table and a PDO insert record call. Will the trigger happen before the return result of the insert statement or will it occur asynchronously? Will it hold up the return result if the trigger takes forever to execute?

Was it helpful?

Solution

It will happen before PDO::query is returning or better spoken, before the mysql server is responding to the client request. This is necessary to keep data health.

The best test to proof this is to put an error into the trigger code and see the error happen in php.

OTHER TIPS

As per MySQL documentation, An error during either a BEFORE or AFTER trigger results in failure of the entire statement that caused trigger invocation.

So, your query will return the result once the trigger finishes its execution or will return the error.

Reference: https://dev.mysql.com/doc/refman/8.0/en/trigger-syntax.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top