First, Note: This app im creating isnt for a website that ill be using, its actually an app that others will be downloading and using in their own networks.
There are plenty of times in my app where a value in the database needs to be populated when the row is inserted or updated...
EG..
- assets.created needs to be set to time() when the asset is created
- assets.modified needs to be updated to time() when the row is updated
- sessions_assoc.regens needs to be set to regens+1 when its updated
Obviously this can be done in the PHP just fine. But ive gotten in the habit of using MySQL Triggers to accomplish this.
EG:
Quote:CREATE TRIGGER assets_list_created BEFORE INSERT ON assets_list FOR EACH ROW SET new.created = UNIX_TIMESTAMP(NOW())
CREATE TRIGGER assets_list_updated BEFORE UPDATE ON assets_list FOR EACH ROW SET new.modified = UNIX_TIMESTAMP(NOW())
It seems to work just fine, except when I have someone else import a MySQL dump and their user is different than mine, but im sure I can find a way around that.
So im just curious how many people use PHP to accomplish these kinds of things, and how many use SQL Triggers.