Peter
Peter

Reputation: 3495

Run MYSQL trigger without updating table

I've just found out about triggers and I'd like to know if this is possible to do somehow. For example, in the site I'm making, one table of IP addresses has LastActivity updated on page load, but that's it.

Could I write this as a trigger and maybe do something like UPDATE (iptable) WHERE Address = (ipaddress), so that while it technically won't update anything, it'll run the trigger on the matching row?

Upvotes: 2

Views: 399

Answers (2)

kwalski
kwalski

Reputation: 608

In short: no. When you say "updated on page load" the "page" is served by an application server (guessing php as per your tag?). The page is not served directly from the database. So, your application server needs to tell mysql to update iptable through a query.

Upvotes: 1

Dmytrechko
Dmytrechko

Reputation: 598

Triggers triggered when you perform type of operation that you bind trigger with. If you bind your trigger to update, it will be executed with no depends on what data you try to update. But you should read about update statements and triggers

For your needs you can use this one:

UPDATE iptable SET Address = Address WHERE Address = ipaddress;

Upvotes: 3

Related Questions