Question

If I do an audit trail using triggers in MySQL, and I use MySQL session variables to store the PHP variables I need to store, something like:

SET @user_id = $user_id
SET @user_ip = $user_ip_address

and then use that information in the trigger, will that work? Is that a good solution?

what I fear is that if multiple users are making queries at the same time the @user_id session variable could change before the trigger is executed and it would be stored in the database as if the other user made the changes.

Can it happen?

Was it helpful?

Solution

So far as I know, variables are session-only, so you could have a thousand sessions using the same variable name without there being overlap.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top