Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. <?php
  2.  
  3. function checkTable($table, $connector) {
  4. $q = "SELECT * FROM `$table` LIMIT 100";
  5. $rows = $connector->query($q)->fetchAll();
  6.  
  7. $rows = array_map(function($row){
  8. return implode($row, '::');
  9. }, $rows);
  10.  
  11. $rows = implode($rows, PHP_EOL);
  12.  
  13. return sha1($rows);
  14. }
  15.  
  16. function checkDB($db, $connector1, $connector2) {
  17. $connector1->query("USE {$db}");
  18. $connector2->query("USE {$db}");
  19.  
  20. $tables = $connector1->query("SHOW TABLES")->fetchAll(PDO::FETCH_OBJ);
  21.  
  22. printf("%20s: %d tables found".PHP_EOL, $db, count($tables));
  23.  
  24. foreach($tables as $table) {
  25. $table = $table->{"Tables_in_$db"};
  26.  
  27. $hash1 = checkTable($table, $connector1);
  28. $hash2 = checkTable($table, $connector2);
  29.  
  30. printf("%20s: %50s = %s %s [ %s ]".PHP_EOL, $db, $table, $hash1, $hash2, $hash1 === $hash2 ? 'OK' : 'ER');
  31. }
  32. }
  33.  
  34. $user = '----';
  35. $pass = '----';
  36.  
  37. $db1 = new PDO('mysql:host=<HOST>', $user, $pass);
  38. $db2 = new PDO('mysql:host=<HOST>;', $user, $pass);
  39. // $db2 = new PDO('mysql:host=<HOST>;', $user, $pass);
  40.  
  41. $stm = $db1->query("SHOW DATABASES");
  42.  
  43. $databases = $stm->fetchAll(PDO::FETCH_OBJ);
  44.  
  45. $skipDBS = ['information_schema'];
  46.  
  47. foreach ($databases as $db) {
  48. if (in_array($db->Database, $skipDBS)) continue;
  49.  
  50. checkDB($db->Database, $db1, $db2);
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement