[Phpwm] MySQL triggers, creating hashed id
Elliot Smith
elliot at townx.org
Fri Aug 17 18:14:07 BST 2007
pete graham wrote:
>> Just a thought, does LAST_INSERT_ID() work in the trigger context? Could
>> you use that in an AFTER trigger?
>>
>
> I'm not sure if LAST_INSERT_ID() will work but you still have the
> problem that it appears you can't update values in the table
> causing/calling the trigger from the AFTER trigger (see comments here
> http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html).
>
> I think I will have to insert then have a update query, how inelegant ;-(
>
You can apply a hash while inserting, as MySQL has a SHA1() function, e.g.
"INSERT INTO table(id, another_field) VALUES(SHA1('myid'), 'some other
stuff');"
I thought you'd discounted this for some reason, e.g. so that any time
you insert a record you don't have to remember to do the hash, as the
database will do it for you. If you're happy to do it during the insert,
you can either do the above in the SQL, or do it in PHP, which also has
a sha1 function.
Elliot
> _______________________________________________
> Phpwm mailing list
> Phpwm at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/phpwm
>
> _______________________________________________
> Phpwm mailing list
> Phpwm at mailman.lug.org.uk
> https://mailman.lug.org.uk/mailman/listinfo/phpwm
>
More information about the Phpwm
mailing list