/** * Test * * * @return void * */ public function testBasicSQLiteTest() { $file_db = new \PDO('sqlite:school.sqlite3'); $file_db->exec('DROP TABLE IF EXISTS [teacher]'); $file_db->exec('DROP TABLE IF EXISTS [course]'); $file_db->exec('DROP TABLE IF EXISTS [person]'); $file_db->exec('DROP TABLE IF EXISTS [student]'); // Create table messages $file_db->exec("CREATE TABLE [teacher] (\n [id] INTEGER PRIMARY KEY AUTOINCREMENT, \n [first_name] VARCHAR(40), \n [last_name] VARCHAR(40), \n [email] VARCHAR(250));"); // Create table messages $file_db->exec("CREATE TABLE [course] (\n [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, \n [start] DATETIME NOT NULL, \n [end] DATETIME NOT NULL, \n [teacher_id] CHAR NOT NULL CONSTRAINT [FK_course_teacher] REFERENCES [teacher]([id]));"); // Create table messages $file_db->exec("CREATE TABLE [person] (\n [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, \n [first_name] VARCHAR(40) NOT NULL, \n [last_name] VARCHAR(40) NOT NULL, \n [email] VARCHAR(250) NOT NULL, \n [identity] created NOT NULL);"); // Create table messages $file_db->exec("CREATE TABLE [student] (\n [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, \n [person_id] INTEGER NOT NULL CONSTRAINT [FK_student_person] REFERENCES [person]([id]), \n [course_id] INTEGER NOT NULL CONSTRAINT [FK_student_course] REFERENCES [course]([id]), \n [created] DATETIME NOT NULL, \n [aborted] DATETIME);"); $cdbyuml = new \Dlid\DbYuml\CDbYuml($file_db, ['scale' => 100, 'style' => 'scruffy', 'cachetime' => '15 minutes']); $cdbyuml->outputImage(); return $cdbyuml; }
}); $app->router->add('', function () use($app, $di) { $app->theme->setTitle("Yuml test"); $imgSrc = $app->url->create('dbdiagram'); $debugUrl = $app->url->create('dbdebug'); $html = <<<EOD <h1>Generated database diagram</h1> <p>This example make use of CDatabase to generate a database diagram</p> <p>[ <a href="{$debugUrl}">show debug info</a> ]</p> <img src='{$imgSrc}' /> EOD; $app->views->add('me/page', ['content' => $html, 'byline' => null]); }); // Include support for generating yUML diagrams $di->set('yuml', function () use($di) { $db = new \Dlid\DbYuml\CDbYuml(); $db->setOptions(['cachepath' => 'dali14', 'dialect' => 'sqlite', 'query' => function ($query, $parameters) use($di) { $di->db->execute($query, $parameters); return $di->db->fetchAll(); }]); return $db; }); $app->router->add('dbdiagram', function () use($app, $di) { $app->theme->setTitle("Yuml test"); $di->yuml->outputImage(); }); $app->router->add('dbdebug', function () use($app, $di) { // By passing true as parameter, all caching will be ignored // This is to make sure all queries are executed so they will be available // for review $di->yuml->outputText(true);
[first_name] VARCHAR(40), [last_name] VARCHAR(40), [email] VARCHAR(250));"); // Create table messages $file_db->exec("CREATE TABLE [course] ( [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [start] DATETIME NOT NULL, [end] DATETIME NOT NULL, [teacher_id] CHAR NOT NULL CONSTRAINT [FK_course_teacher] REFERENCES [teacher]([id]));"); // Create table messages $file_db->exec("CREATE TABLE [person] ( [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [first_name] VARCHAR(40) NOT NULL, [last_name] VARCHAR(40) NOT NULL, [email] VARCHAR(250) NOT NULL, [identity] created NOT NULL);"); // Create table messages $file_db->exec("CREATE TABLE [student] ( [id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, [person_id] INTEGER NOT NULL CONSTRAINT [FK_student_person] REFERENCES [person]([id]), [course_id] INTEGER NOT NULL CONSTRAINT [FK_student_course] REFERENCES [course]([id]), [created] DATETIME NOT NULL, [aborted] DATETIME);"); */ $cdbyuml = new \Dlid\DbYuml\CDbYuml($file_db, ['scale' => 230, 'style' => 'scruffy', 'cachepath' => 'dlid14.mh', 'cachetime' => '15 minutes']); $cdbyuml->outputText(); // Uncommen to see debug information # ->outputImage(true);
<?php require '../autoloader.php'; $dbh = new PDO('mysql:host=localhost;dbname=ames;', 'root', '3UfRAwak', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'')); $cdbyuml = new \Dlid\DbYuml\CDbYuml($dbh, ['cachepath' => 'mysql_example', 'cachetime' => '15 minutes']); $cdbyuml->outputText(true)->outputImage();