1
0
mirror of https://github.com/dg/dibi.git synced 2025-01-17 14:18:25 +01:00
php-dibi/examples/database-reflection.php

50 lines
1.1 KiB
PHP
Raw Normal View History

2010-08-03 21:06:56 +02:00
<!DOCTYPE html><link rel="stylesheet" href="data/style.css">
<h1>Database Reflection | dibi</h1>
<?php
2015-01-13 16:27:01 +01:00
require __DIR__ . '/../src/loader.php';
2010-08-03 21:06:56 +02:00
2015-10-06 01:39:01 +02:00
dibi::connect([
2015-06-19 03:11:36 +02:00
'driver' => 'sqlite3',
'database' => 'data/sample.s3db',
2015-10-06 01:39:01 +02:00
]);
2010-08-03 21:06:56 +02:00
// retrieve database reflection
$database = dibi::getDatabaseInfo();
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";