Advertisement
Guest User

Untitled

a guest
Apr 13th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. <?php
  2.  
  3. function connect($db) {
  4. $host = '127.0.0.1';
  5. $user = 'root';
  6. $pass = '';
  7. $charset = 'utf8mb4';
  8.  
  9. $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
  10.  
  11. $options = [
  12. PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
  13. PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
  14. PDO::ATTR_EMULATE_PREPARES => FALSE,
  15. ];
  16.  
  17. try {
  18. $pdo = new PDO($dsn, $user, $pass, $options);
  19. } catch (\PDOException $e) {
  20. throw new \PDOException($e->getMessage(), (int) $e->getCode());
  21. }
  22.  
  23. return $pdo;
  24. }
  25.  
  26. function tables($pdo, $database_name) {
  27. $stmt = $pdo->query("select table_name from information_schema.tables where table_schema = '" . $database_name . "'" );
  28.  
  29. while ($row = $stmt->fetch()) {
  30. $tables[] = $row['table_name'];
  31. }
  32.  
  33. return $tables;
  34. }
  35.  
  36. function count_rows($pdo, $table_name){
  37. $stmt = $pdo->query('SELECT count(*) as count FROM ' . $table_name);
  38. return $stmt->fetch()['count'];
  39. }
  40.  
  41. $local_preprod = connect('local_preprod');
  42. $preprod = connect('preprod');
  43. $information_schema = connect('information_schema');
  44.  
  45. $local_preprod_tables = tables($information_schema, 'local_preprod');
  46. $preprod_tables = tables($information_schema, 'preprod');
  47.  
  48.  
  49. $local_preprod_tables_counted = [];
  50. foreach ($local_preprod_tables as $table){
  51. $local_preprod_tables_counted[$table] = count_rows($local_preprod, $table);
  52. }
  53.  
  54. $preprod_tables_counted = [];
  55. foreach ($preprod_tables as $table){
  56. $preprod_tables_counted[$table] = count_rows($preprod, $table);
  57. }
  58.  
  59. foreach ($local_preprod_tables_counted as $key => $value) {
  60. if (key_exists($key, $preprod_tables_counted) && ($value != $preprod_tables_counted[$key])) {
  61. print_r('table : ' . $key . ' local_preprod ' . $value . ' preprod ' . $preprod_tables_counted[$key] . "\n");
  62. }
  63. }
  64.  
  65. var_dump($local_preprod_tables_counted['node__field_occupation_synonym']);
  66. var_dump($preprod_tables_counted['node__field_occupation_synonym']);
  67.  
  68. //var_dump(count($local_preprod_tables));
  69. //var_dump(count($preprod_tables));
  70. //var_dump(array_diff($local_preprod_tables, $preprod_tables));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement