przemo_li
przemo_li

Reputation: 4053

Log all queries to SQL Server made from single PHP script that use ODBC module?

I have 1,5k lines od PHP spaghetti code that have dozens of if's generating dozens more queries.

All the conditions are simple "==" or "!=" against list of ~20 possibilities.

Now I need to add 21st... I need to:

How can I enable query logging ( ext of executed query will be enough ) for just that single .php file if code use ODBC php module to talk to SQL Server?

Upvotes: 0

Views: 313

Answers (1)

Robert Paulsen
Robert Paulsen

Reputation: 5151

You can user SQL Server Profiler. It will be installed on the server or anywhere you have SQL Sever Management Tools installed. Normally something like this:

"C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\PROFILER.EXE"

  1. Start SQL Profiler
  2. Enter the server info, click Connect
  3. Choose a template. I suggest you choose "Duration" because by default it only logs commands that have completed.
  4. Click RUN.
  5. Click around in your application and you'll see your SQL statements execute.

If there's a lot happening on your server. You will see a TON of stuff go by and realize it's too much to comprehend. So my suggestion is:

  1. Update your connection string to include:

"Application Name=MyAppNameHere;"

  1. Before Step 4, go under the "Events Selection" tab.
  2. Check "Show all columns"
  3. Place a checkmark under "ApplicationName"
  4. Click "Column Filters" button
  5. Select "Application Name" on left.
  6. under "Like" enter "MyAppNameHere".
  7. Click Run

Now when you click around in your application it will only log things that you are doing.

You can have this data dropped to a table or a file or you can just look at what is outputted to the screen.

You may find it's helpful to add other columns or events.

Upvotes: 1

Related Questions