0

I can find out that certain query has been fired to MySQL database from the mysqlBinLog. But is there a way to find which PHP file has executed those queries ?

My problem is- I am not able to trace which php file in the Application is firing a particular update query.

I have searched in the whole application for that particular update query but I didn't find any match. It is generated programatically somewhere and get executed.

Since the code footprint is too big, it is practically not possible for me to go and put a log statement everywhere.

4

2 回答 2

3

You can wrap a logger class around the database access library (PDO) and log the query together with a backtrace.

class LoggerPDO extends PDO
{
    function query()
    {
        return $this->logger('query', func_get_args());
    }

    private function logger($method, $args)
    {
        // log query
        debug_print_backtrace();
        // push to parent
        return call_user_func_array(array($this, 'parent::' . $method), $args);
    }
}

You can add other methods that need logging too, such as prepare() or execute().

If you're using mysql_ functions, good luck :)

于 2012-05-21T07:27:46.070 回答
0

U can put logs from where update queries are fired and get these logs info

于 2012-05-21T07:26:42.143 回答