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);
?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.