mirror of
https://github.com/dg/dibi.git
synced 2025-01-17 14:18:25 +01:00
examples: added new
This commit is contained in:
parent
dc62e87629
commit
f3c2c27818
BIN
examples/data/sample.s3db
Normal file
BIN
examples/data/sample.s3db
Normal file
Binary file not shown.
53
examples/database-reflection.php
Normal file
53
examples/database-reflection.php
Normal file
@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html><link rel="stylesheet" href="data/style.css">
|
||||
|
||||
<h1>Database Reflection | dibi</h1>
|
||||
|
||||
<?php
|
||||
|
||||
require_once 'Nette/Debug.php';
|
||||
require_once '../dibi/dibi.php';
|
||||
|
||||
|
||||
dibi::connect(array(
|
||||
'driver' => 'sqlite',
|
||||
'database' => 'data/sample.sdb',
|
||||
));
|
||||
|
||||
|
||||
|
||||
// retrieve database reflection
|
||||
$database = dibi::getDatabaseInfo();
|
||||
|
||||
echo "<h2>Database '{$database->name}'</h2>\n";
|
||||
echo "<ul>\n";
|
||||
foreach ($database->getTables() as $table) {
|
||||
echo '<li>', ($table->view ? 'view' : 'table') . " $table->name</li>\n";
|
||||
}
|
||||
echo "</ul>\n";
|
||||
|
||||
|
||||
|
||||
// table reflection
|
||||
$table = $database->getTable('products');
|
||||
|
||||
echo "<h2>Table '{$table->name}'</h2>\n";
|
||||
|
||||
echo "Columns\n";
|
||||
echo "<ul>\n";
|
||||
foreach ($table->getColumns() as $column) {
|
||||
echo "<li>{$column->name} <i>{$column->nativeType}</i> <code>{$column->default}</code></li>\n";
|
||||
}
|
||||
echo "</ul>\n";
|
||||
|
||||
|
||||
|
||||
echo "Indexes";
|
||||
echo "<ul>\n";
|
||||
foreach ($table->getIndexes() as $index) {
|
||||
echo "<li>{$index->name} " . ($index->primary ? 'primary ' : '') . ($index->unique ? 'unique' : '') . ' (';
|
||||
foreach ($index->getColumns() as $column) {
|
||||
echo "$column->name, ";
|
||||
}
|
||||
echo ")</li>\n";
|
||||
}
|
||||
echo "</ul>\n";
|
@ -92,5 +92,3 @@ dibi::test("
|
||||
// indentifiers and strings syntax mix
|
||||
dibi::test('UPDATE [table] SET `item` = "5 1/4"" diskette"');
|
||||
// -> UPDATE [table] SET [item] = '5 1/4" diskette'
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user