<?php
require_once('../config.php');
require_once('../'.PATH_CORE.'ErrorHandler.php');
require_once('../'.PATH_CORE.'Database.php');

$errorHandler = new ErrorHandler();
$database = new Database(DB_SERVER, DB_USER, DB_PASS, DB_NAME);

$mes = '';
$file = ROOT_DIR.'sandbox_scripts/database_structure/tables.txt';
$sql ="SHOW TABLES";
$query = $database->query($sql);
while($row = $database->fetchArray($query)){
    $sqlTable = "DESCRIBE ".$row['Tables_in_ricoh_dash'];
    $queryTable = $database->query($sqlTable);

    $mes .= $row['Tables_in_ricoh_dash'] . PHP_EOL;
    $mes .= '-------------------------------------------------------' . PHP_EOL;
    while ($tableCol = $database->fetchArray($queryTable)){
        foreach ($tableCol as $key => $value) {
            $mes .= $key . ' : ' . $value . PHP_EOL;
        }
        $mes .= PHP_EOL;
    }
    $mes .= '-------------------------------------------------------' . PHP_EOL;
    $mes .= PHP_EOL;
}

file_put_contents($file, $mes);
echo PHP_EOL . 'Database structure saved!' . PHP_EOL;
?>
