[Phpwm] MySQL triggers, creating hashed id

pete graham petegraham1 at gmail.com
Fri Aug 17 16:15:35 BST 2007


Regarding my last problem I have decided to store items in my database
with a hash of each items id. Ideally I'd like to do this using
triggers to keep everything nice and clean. However I'm feeling quite
dumb today and can't work out how to do it. Here's my attempt:

CREATE TRIGGER clips_create_hash BEFORE INSERT ON `clips` FOR EACH ROW SET
NEW.id_hash = sha1(NEW.id);

This ends up setting all the hashes the same, I believe that it's
getting 0 for the value of NEW.id. This makes sense since id is a
auto-incrementing primary key so wouldn't exist before the insert. But
if I try to change the trigger to make it 'AFTER' I get this:

"Updating of NEW row is not allowed in after trigger"

Any help greatly appreciated.

Thanks, Pete



More information about the Phpwm mailing list