0

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?

Florent
  • 12,310
  • 10
  • 49
  • 58
F. A
  • 111
  • 1
  • 10

1 Answers1

0

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.

Andrew
  • 5,095
  • 6
  • 42
  • 48