Database Reflection | Dibi
'sqlite',
'database' => 'data/sample.s3db',
]);
// retrieve database reflection
$database = $dibi->getDatabaseInfo();
echo "Database '{$database->getName()}'
\n";
echo "\n";
foreach ($database->getTables() as $table) {
echo '- ', ($table->isView() ? 'view' : 'table') . " {$table->getName()}
\n";
}
echo "
\n";
// table reflection
$table = $database->getTable('products');
echo "Table '{$table->getName()}'
\n";
echo "Columns\n";
echo "\n";
foreach ($table->getColumns() as $column) {
echo "- {$column->getName()} {$column->getNativeType()}
{$column->getDefault()}
\n";
}
echo "
\n";
echo 'Indexes';
echo "\n";
foreach ($table->getIndexes() as $index) {
echo "- {$index->getName()} " . ($index->isPrimary() ? 'primary ' : '') . ($index->isUnique() ? 'unique' : '') . ' (';
foreach ($index->getColumns() as $column) {
echo $column->getName(), ', ';
}
echo ")
\n";
}
echo "
\n";