So, I am developing a system in PHP + MySQL which has about 4 related tables. Any form of Insert,Update, and Delete in one table typically reflects across at least 2 tables.
My question is, what is more efficient, the use of triggers or additional php script (which triggers SQL queries) to take care of the required related changes?
Triggers seems ideal to me, but when I write them they become pretty complicated and messy from readability point of view. PHP allows for a more “sane” way of doing things.
Please suggest on the basis of both, performance as well as usability/future modifications etc.
I would strongly suggest that you construct your database to look after itself.
It is called decoupling.
Then even it there is a mistake in your (or somebody else) script the data is protected. For most (all?) business that is the most important asset.
Also it enables one to use other mechanisms to utilize the database. Even the raw command line.
To make the code more readable – format it and use comments.