logs in phpMyAdmin

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

logs in phpMyAdmin

Post by jasongr »

Hello

I am using phpMyAdmin
Does anyone know whether phpMyAdmin logs operations done in the database?
Like who deleted entries? who added entries?
If so, where can such logs be found?

regards
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It doesn't log by default and I don't remember logging functions the last time I ran through the code (other than debug stuff for their code). From what I remember, logging would be a setting you tell MySQL to do.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

You can use MySQL binlog (binary logging facility) for this. Here is handy script to search through binlog for particular statements:

Code: Select all

#!/bin/php -q
<?php
        set_time_limit(0);

        $regexp = $argv[1];
        if(!$regexp) {
                die("DiE hard! You used this script in the wrong way.\n");
        }
        var_dump($regexp);

        $logs = array();
        if(empty($argv[2])) {
                $logs = getLogs('binlog-bin.index');
        } else {
                $logs[] = basename($argv[2]);
        }
        if(strpos(end($logs), ",") !== false) {
                $logs = explode(",", end($logs));
        }

        foreach($logs as $log) {
                echo "=============$log=============\n";
                foreach(grepFor($regexp, $log) as $query) {
                        echo $query . "\n\n";
                }
        }


        function grepFor($regexp, $filename) {
                $ret = array();
                $current_query = '';
                $fp = getLogPipe(basename($filename));
                while(!feof($fp)) {
                        $line = trim(fgets($fp));
                        if(preg_match('/log_pos\s+(\d+)/', $line, $matches)) {

                                if(preg_match($regexp . 'm', $current_query)) {
                                        $ret[] = $current_query;
                                }

                                $current_query = '';
                        } elseif(!preg_match('/^#/', $line)) {
                                $current_query .= "\n" . $line;
                        }

                }
                pclose($fp);
                return $ret;
        }


        function getLogPipe($log) {
                $fp = popen('mysqlbinlog ' . $log . ' 2>&1', 'r');
                return $fp;
        }

        function getLogs($filename) {
                return array_map(create_function('$name', 'return trim($name);'), file($filename));
        }

        function getUnprocessedLogs($logs) {
                global $current_log;
                $ret = $logs;
                if(false !== ($index = array_search($current_log, $logs))) {
                        $ret = array_slice($logs, $index);
                }
                return $ret;
        }
?>
jasongr
Forum Contributor
Posts: 206
Joined: Tue Jul 27, 2004 6:19 am

thanks

Post by jasongr »

I will read more about this stuff
Post Reply