Hi…
While finding my way around a new code base, I needed a way of poking things and seeing what happens. So I hacked together a quick tool over an afternoon and an evening.
To use it just point it at two databases and click “Show differences”. Rows in the first DB only are green, rows in the second (reference DB) are in red.
If you don’t have a second DB and cannot be bothered with a dump/restore to get one, then name the second DB and click “Clone –>”. That will create a copy (less indexes, so watch out) that you can then use as reference.
I’ve been using it something like: “I wonder what this does?”, clone the DB, try the thing, observe the differences, restore the DB back to the last snapshot.
There are a bunch of improvements I could make. Most notably the duplicating of indexes would allow me to add a “<– Clone” button to restore the DB to it’s previous state without needing mysqldump. It would also be nice to have the form labels above the text fields, but I couldn’t remember the necessary CSS.
yours, Marcus
p.s. I do like the way you can ship an entire mini application in a single script with PHP :).
p.p.s. I still can’t believe after all these years of running a PHP forum that SitePoint doesn’t allow you to attach a PHP file without tacking on a useless .txt extension :(.
Hi…
As an old(ish) C coder I never have a problem with these constructs. I’ll change it next time I play with the code.
Did you try the script out?
yours, Marcus
I don’t have a GitHub account yet, so I’m going to post this here.
You have a likely error on line 64, with this function definition:
function sql($sql) {
if ($result = mysql_query($sql, connection())) {
return is_resource($result) ? all_rows($result) : array();
}
throw new Exception(mysql_error(connection()) . " with [$sql]");
}
The if statement makes an assignment instead of a comparison. Not sure if that’s on purpose.
Also, off topic: Ewww, ternary operators.
Edit:After re-reading the code, I see what you were trying to do there. I’d recommend refactoring that to have the comparison and the assignment on two different lines.
I don’t see a license mentioned. Is it safe to assume that we may use/modify/recommit patches without fear of retribution?
kyberfrabrikken: seems to me that your script can’t really work, because credentials format required by mysqljsondump differs from that required by mysql binary. For example: --user [username] vs. --user=[username] and --pass [password] vs. --password=[password].
Funny - I did the same a few months back: http://github.com/troelskn/mysqldatadiff
Now I’ll have to look at yours to see how much they differ. (Excuse the pun)
Hi…
Inspired by Troels I’ve started a github account:
http://github.com/lastcraft/Mysql-diff
yours, Marcus