Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8014417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:55:36+00:00 2026-06-04T19:55:36+00:00

I need to do some comprehensive auditing on a MySQL database that will be

  • 0

I need to do some comprehensive auditing on a MySQL database that will be accessed using a Symfony2 app.

As far as I’m aware, standard practice is to insert into the audit table the value returned by the built-in MySQL function USER() to log who is making the changes to the records. Since all changes to the database will be performed through the Symfony2 frontend with the database connection parameters specified in the parameters.ini file, USER() will always return the same value. To get around this, I am using a MySQL session variable, @sf_user. I can get the username from the Symfony session object and use it to set the value of @sf_user in my controllers e.g.

$em = $this->getDoctrine()->getEntityManager();
// set @sf_user session variable in the database
// so trigger can insert this in audit table after delete
$conn = $em->getConnection();
$username = $this->get('security.context')->getToken()->getUser()->getUsername();
$sql = 'SET @sf_user = \''.$username.'\'';
$stmt = $conn->prepare($sql);
$stmt->execute();

This is fine, but as I am auditing all my tables and can’t predict which action the user will perform first, I would need to repeat this code in every controller to ensure @sf_user is set at the start of the session.

What I would really like to do is to set this variable when the user logs in. I have set up my login page as described in The Book. The problem is, my SecurityController only handles displaying the login form, while “the security system itself takes care of checking the submitted username and password and authenticating the user”.

So, my question is, where can I insert the above code so that it is always executed at the start of the session, after the user has successfully logged in?

Many Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:55:38+00:00Added an answer on June 4, 2026 at 7:55 pm

    Thanks for all suggestions, I have just gone back to setting the variable @sf_user in each deleteAction controller. It’s not pretty , but it works.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some guidance figuring out what went wrong. I've been using mysql, phpmyadmin for
Need some help with putting this query together. I'm using Mysql I have two
Need some help assigning a mouseover event to display some icons that start out
Need some help with DataFormatString in GridView. I have a Double value that needs
Need some help, I have a regular expression that appears to work just fine
Need some help refactoring this if/else block that builds the conditions for a find
I have an MVC 3 app that I'm building, and need to figure out
Need some regular expressions help. So far I have my code working to allow
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help to solve this. I have a gridview and inside the gridview

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.