2017-07-21 21:34:37 +02:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
?>
|
2010-08-03 21:06:56 +02:00
|
|
|
<!DOCTYPE html><link rel="stylesheet" href="data/style.css">
|
|
|
|
|
2018-05-10 21:45:11 +02:00
|
|
|
<h1>Database Reflection | Dibi</h1>
|
2010-08-03 21:06:56 +02:00
|
|
|
|
|
|
|
<?php
|
|
|
|
|
2018-03-23 11:57:59 +01:00
|
|
|
if (@!include __DIR__ . '/../vendor/autoload.php') {
|
|
|
|
die('Install packages using `composer install`');
|
|
|
|
}
|
2010-08-03 21:06:56 +02:00
|
|
|
|
|
|
|
|
2018-04-17 10:03:43 +02:00
|
|
|
$dibi = new Dibi\Connection([
|
2018-05-23 17:08:25 +02:00
|
|
|
'driver' => 'sqlite',
|
2012-10-18 23:00:12 +02:00
|
|
|
'database' => 'data/sample.s3db',
|
2015-10-06 01:39:01 +02:00
|
|
|
]);
|
2010-08-03 21:06:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
// retrieve database reflection
|
2018-04-17 10:03:43 +02:00
|
|
|
$database = $dibi->getDatabaseInfo();
|
2010-08-03 21:06:56 +02:00
|
|
|
|
2015-10-06 13:14:01 +02:00
|
|
|
echo "<h2>Database '{$database->getName()}'</h2>\n";
|
2010-08-03 21:06:56 +02:00
|
|
|
echo "<ul>\n";
|
|
|
|
foreach ($database->getTables() as $table) {
|
2015-10-06 13:14:01 +02:00
|
|
|
echo '<li>', ($table->isView() ? 'view' : 'table') . " {$table->getName()}</li>\n";
|
2010-08-03 21:06:56 +02:00
|
|
|
}
|
|
|
|
echo "</ul>\n";
|
|
|
|
|
|
|
|
|
|
|
|
// table reflection
|
|
|
|
$table = $database->getTable('products');
|
|
|
|
|
2015-10-06 13:14:01 +02:00
|
|
|
echo "<h2>Table '{$table->getName()}'</h2>\n";
|
2010-08-03 21:06:56 +02:00
|
|
|
|
|
|
|
echo "Columns\n";
|
|
|
|
echo "<ul>\n";
|
|
|
|
foreach ($table->getColumns() as $column) {
|
2015-10-06 13:14:01 +02:00
|
|
|
echo "<li>{$column->getName()} <i>{$column->getNativeType()}</i> <code>{$column->getDefault()}</code></li>\n";
|
2010-08-03 21:06:56 +02:00
|
|
|
}
|
|
|
|
echo "</ul>\n";
|
|
|
|
|
|
|
|
|
2015-06-19 03:11:36 +02:00
|
|
|
echo 'Indexes';
|
2010-08-03 21:06:56 +02:00
|
|
|
echo "<ul>\n";
|
|
|
|
foreach ($table->getIndexes() as $index) {
|
2015-10-06 13:14:01 +02:00
|
|
|
echo "<li>{$index->getName()} " . ($index->isPrimary() ? 'primary ' : '') . ($index->isUnique() ? 'unique' : '') . ' (';
|
2010-08-03 21:06:56 +02:00
|
|
|
foreach ($index->getColumns() as $column) {
|
2015-10-06 13:14:01 +02:00
|
|
|
echo $column->getName(), ', ';
|
2010-08-03 21:06:56 +02:00
|
|
|
}
|
|
|
|
echo ")</li>\n";
|
|
|
|
}
|
|
|
|
echo "</ul>\n";
|