New onsite patient portal, take 4.
[openemr.git] / portal / patient / fwk / libs / verysimple / DB / Reflection / DBSchema.php
blob788a857e44a908fcf2dceb1a9a3470ac9333aead
1 <?php
2 /** @package verysimple::DB::Reflection */
4 /**
5 * import supporting libraries
6 */
7 require_once ("DBTable.php");
9 /**
10 * DBSchema is an object representation of a MySQL Schema/Database
12 * @package verysimple::DB::Reflection
13 * @author Jason Hinkle
14 * @copyright 1997-2007 VerySimple, Inc.
15 * @license http://www.gnu.org/licenses/lgpl.html LGPL
16 * @version 1.0
18 class DBSchema {
19 public $Server;
20 public $Name;
21 public $Tables;
23 /**
24 * Instantiate new DBSchema
26 * @access public
27 * @param DBServer $server
28 * @param string $name
29 * name of schema to parse
31 function __construct($server) {
32 $this->Server = & $server;
33 $this->Name = $server->Connection->DBName;
34 $this->Tables = Array ();
36 $this->Load ();
38 // print "<pre>"; print_r($this->Tables["ticket"]); die();
41 /**
42 * Inspects the current schema and loads all tables, keys, etc.
44 * @access public
46 private function Load() {
47 $sql = "show tables";
48 $rs = $this->Server->Connection->Select ( $sql );
50 // first pass load all the tables. this will initialize each object. we have to
51 // do this first so that we can correctly determine and store "Set" information
52 while ( $row = $this->Server->Connection->Next ( $rs ) ) {
53 $this->Tables [$row ["Tables_in_" . $this->Name]] = new DBTable ( $this, $row );
56 // now load all the keys and constraints for each table
57 foreach ( $this->Tables as $table ) {
58 $table->LoadKeys ();
61 $this->Server->Connection->Release ( $rs );
63 $sql = "show table status from `" . $this->Name . "`";
64 $rs2 = $this->Server->Connection->Select ( $sql );
66 // load the extra data
67 while ( $row = $this->Server->Connection->Next ( $rs2 ) ) {
68 $this->Tables [$row ["Name"]]->Engine = $row ["Engine"];
69 $this->Tables [$row ["Name"]]->Comment = $row ["Comment"];
71 $this->Server->Connection->Release ( $rs2 );