Welcome Guest, Not a member yet? Register   Sign In
Poll: Straight PHP or SQL Trigger
You do not have permission to vote in this poll.
PHP All the way!
80.00%
4 80.00%
SQL Triggers
20.00%
1 20.00%
Total 5 vote(s) 100%
* You voted for this item. [Show Results]

Database - Triggers or no Triggers?
#1

(This post was last modified: 08-27-2015, 12:35 PM by jLinux.)

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.
Reply


Messages In This Thread
Database - Triggers or no Triggers? - by jLinux - 08-27-2015, 10:55 AM
RE: Database - Triggers or no Triggers? - by Narf - 09-01-2015, 02:16 AM
RE: Database - Triggers or no Triggers? - by Narf - 09-01-2015, 05:49 AM



Theme © iAndrew 2016 - Forum software by © MyBB