Jump to content

Capture all mysql queryies?


ac1982

Recommended Posts

I would probably go about it like this.  I used an array and just declared it global in the function but personally I would have a logging function that would log the queries rather than just adding them to an array.  Anyway this will be a  dimensional array that will look like this:

$array['select'] = array("first select type query", "second select type query", "etc...");

$array['insert'] = array("first insert type query", "second insert type query", "etc...");

$array['update'] = array("first update type query", "second update type query", "etc...");

 

<?php
$queryLog = array();
$dbconn = someMysqlConnectFunction();

function runQuery($query, $dbconn)
{
global $queryLog;

list($querytype) = explode(" ", strtolower(trim($query)));

$queryLog[$querytype][] = $query;

return mysql_query($query, $dbconn);
}

$result = runQuery("select * from tablename where column = 'value'", $dbconn);
?>

Link to comment
Share on other sites

Mysql has a query log that logs the date/time, mysql user name, and the actual query. Otherwise you would need to add code to your script at each mysql_query() statement or if you are using a database class, to the common point in the class code that executes a mysql_query() to do what you want. The php error_log() function is intended for this purpose.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.