Database Checker is a set of PHP functions to check and compare MySQL databases

Use cases and Reference

Database Checker only create SQL queries. It's safe, as long as you DON'T run these queries. If you do, this may lead to DATA LOSS! So before running an SQL query, make sure you understand it. If you don't, don't run it. You've been warned.

Say you have the following MySQL settings:
Hostname: localhost
User: my_user
Password: paSSworD
Databases: my_database1 and my_database2

First, start with a declaration of your MySQL server:
$dbc = new Database_Checker();
$server1 = $dbc->addServer('server1', 'localhost', 'my_user', 'paSSworD');

Then select what databases (schemas) you'll compare:
$dbc->selectDatabase('server1', 'my_database1', true); // sets this database as the master for differences
$dbc->selectDatabase('server1', 'my_database2', false);

Almost all functions need both a master (true) and a slave (false) databases. Note that calling again selectDatabase() will change either the master or the slave (there's only one master and one slave). This may be useful if you have many databases to check, you just call selectDatabase() then issue the comparison function you need.

If you run into trouble when running one function, don't forget to look at errors:

Then, the interesting (I hope so!) part. Need to know what are the differences between these 2 databases (missing tables only)? Use getDatabaseDiff():

Only want schema changes for one specific table? Use getTableColumnsDiff():

Need to check if your foreign keys aren't broken (innodb only)? Use findBrokenKeys():

Want to get full data differences between 2 tables (should be done only on small tables, this is not a replication tool!)? Use getTableDiff():
var_dump($dbc->getTableDiff('my_table', $reverse), $reverse);

Last example: say you have a remote server, you may want to compare it easily. Edit the remote.php found in the package, say you install it at, then use a declaration such as:
$dbc = new Database_Checker();
$server1 = $dbc->addServer('server1', 'localhost', 'my_user', 'paSSworD');
$server2 = $dbc->addServer('server2', 'localhost', 'my_user2', 'paSSworD2', '');

In remote.php, you should then have:
Database_Checker::run('localhost', 'my_user2', 'paSSworD2');
Finally, declare your databases:
$dbc->selectDatabase('server1', 'my_database1', true);
$dbc->selectDatabase('server2', 'my_database1', false);

All data will be transmitted through the Http class (no encryption, so know what you're doing before using this).


More information: