Re: Getting queries from files FYI

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 8/23/05, Jay Blanchard <jay.blanchard@xxxxxxxxxxxxxxxxxxxxx> wrote:
> You may (or may not) remember me posting to the list a couple of weeks
> ago asking about using REGEX to get queries out of PHP files for a
> migration project. I had to let it go for several days, but started
> working on it again yesterday, here is the code (no REGEX was used in
> the making of this code);

Just a thought - and I know it's a little late, sorry.

Have you considered writing a wrapper for mysql_query() that logs its
parameters?

You could:

1. do a search and replace on your code replacing 'mysql_query' with
'mysql_query_wrapper'.

2. put a function definition for mysql_query_wrapper() in an auto_prepend file.

function mysql_query_wrapper()
{
  $args = func_get_args();
  $backtrace = debug_backtrace();
  $details = $backtrace[0];
  log(sprintf("%s (line %d): %s\n", $details['file'],
$details['line'], $details['args'][0]));
  return call_user_func_array('mysql_query', $args);
}

3. Let your users hammer it for a week or so. Your log should then
contain all the queries used by the app on a day-to-day basis and
where they were called from.

5. Do a grep for all lines containing 'mysql_query_wrapper' and diff
it with your log file. That should give you the locations of the
(hopefully few) remaining queries.

cut -d ':' -f 1,2 logfile.txt | sort --unique > recorded_queries.txt

fgrep -n 'mysql_query_wrapper' /path/*.php | cut -d ':' -f 1,2 | sort
--unique > all_queries.txt

comm -3 recorded_queries.txt all_queries.txt

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux