Highway to PSR2
[openemr.git] / portal / patient / fwk / libs / verysimple / DB / Reflection / DBSchema.php
blob51613b8ab20ed9218075a529a203d22955b1003b
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
20 public $Server;
21 public $Name;
22 public $Tables;
24 /**
25 * Instantiate new DBSchema
27 * @access public
28 * @param DBServer $server
29 * @param string $name
30 * name of schema to parse
32 function __construct($server)
34 $this->Server = & $server;
35 $this->Name = $server->Connection->DBName;
36 $this->Tables = array ();
38 $this->Load();
40 // print "<pre>"; print_r($this->Tables["ticket"]); die();
43 /**
44 * Inspects the current schema and loads all tables, keys, etc.
46 * @access public
48 private function Load()
50 $sql = "show tables";
51 $rs = $this->Server->Connection->Select($sql);
53 // first pass load all the tables. this will initialize each object. we have to
54 // do this first so that we can correctly determine and store "Set" information
55 while ($row = $this->Server->Connection->Next($rs)) {
56 $this->Tables [$row ["Tables_in_" . $this->Name]] = new DBTable($this, $row);
59 // now load all the keys and constraints for each table
60 foreach ($this->Tables as $table) {
61 $table->LoadKeys();
64 $this->Server->Connection->Release($rs);
66 $sql = "show table status from `" . $this->Name . "`";
67 $rs2 = $this->Server->Connection->Select($sql);
69 // load the extra data
70 while ($row = $this->Server->Connection->Next($rs2)) {
71 $this->Tables [$row ["Name"]]->Engine = $row ["Engine"];
72 $this->Tables [$row ["Name"]]->Comment = $row ["Comment"];
75 $this->Server->Connection->Release($rs2);