PHP code example of tyty16 / sqldeadcolumnfinder

1. Go to this page and download the library: Download tyty16/sqldeadcolumnfinder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tyty16 / sqldeadcolumnfinder example snippets





$db = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
$sqlDeadColumnFinder = new SQLDeadColumnFinder($db, 'test', false, 6, 'path/to/dir/deadColumns');





$sqlDeadColumnFinder->find();





$tables = array();
$tables = $sqlDeadColumnFinder->getTablesToCheck();





$columns = $sqlDeadColumnFinder->getColumnsToCheck($tables);




  
  $formattedTablesWithColumns = sqlDeadColumnFinder->formatTablesWithColumns($unformattedColumns);
  



  
  $deadColumns = sqlDeadColumnFinder->formatTablesWithColumns($unformattedColumns);
  



  
  sqlDeadColumnFinder->outputToFile($deadColumns);
  

array(2) {
  [0]=>
  array(2) {
    ["TABLE_NAME"]=>
    string(3) "foo"
    ["TABLE_SCHEMA"]=>
    string(4) "test"
  }
  [1]=>
  array(2) {
    ["TABLE_NAME"]=>
    string(3) "bar"
    ["TABLE_SCHEMA"]=>
    string(4) "test"
  }
}



array(3) {
  [0]=>
  array(3) {
    ["TABLE_SCHEMA"]=>
    string(4) "test"
    ["TABLE_NAME"]=>
    string(3) "foo"
    ["COLUMN_NAME"]=>
    string(2) "id"
  }
  [1]=>
  array(2) {
    ["TABLE_SCHEMA"]=>
    string(4) "test"
    ["TABLE_NAME"]=>
    string(3) "foo"
    ["COLUMN_NAME"]=>
    string(2) "name"
  }
  [2]=>
  array(2) {
    ["TABLE_SCHEMA"]=>
    string(4) "test"
    ["TABLE_NAME"]=>
    string(3) "bar"
    ["COLUMN_NAME"]=>
    string(2) "address"
  }
}



array(1) {
  ["test"]=>
  array(2) {
    ["foo"]=>
    array(2) {
      [0]=>
      string(2) "id"
      [1]=>
      string(4) "name"
    }
    ["bar"]=>
    array(1) {
      [0]=>
      string(7) "address"
    }
  }
}



array(1) {
  ["test"]=>
  array(1) {
    ["foo"]=>
    array(2) {
      ["id"]=>
        array(3) {
          ["distinct"]=>
          int(1)
          ["value"]=>
          string(1) "1"
          ["is_null"]=>
          int(0)
        }
      ["name"]=>
        array(3) {
          ["distinct"]=>
          int(0)
          ["value"]=>
          string(4) "NULL"
          ["is_null"]=>
          int(1)
        }
    }
  }
}