afa66798d4ce3836bdddba02ac11e9324228e698
[PHPIPManager.git] / lib / db.php
1 <?php
2
3 // i really dont know why i do another obfuscation layer for db's with adodb.
4 class db {
5         function init() {
6
7                 $sql = 'CREATE TABLE sqlite_sequence(name,seq);';
8                 $this->dbobject->query($sql);
9                 
10                 $sql = 'CREATE TABLE "hosts" ("ho_id" INTEGER PRIMARY KEY AUTOINCREMENT,"ho_sn_id" INTEGER,"ho_ip" TEXT,"ho_name" TEXT,"ho_desc" TEXT);';
11                 $this->dbobject->query($sql);
12                 
13                 $sql = 'CREATE TABLE subnet ("sn_id" INTEGER,"snid_id" INTEGER,"sn_ip" TEXT,"sn_mask" TEXT,"sn_name" TEXT, "sn_desc" TEXT);';
14                 $this->dbobject->query($sql);
15                 
16                 $sql = 'CREATE TABLE supernet ("sn_id" INTEGER,"sn_name" TEXT,"sn_ip" TEXT,"sn_mask" TEXT,"sn_desc" TEXT);';
17                 $this->dbobject->query($sql);
18         }
19         
20         function connect() {
21                 global $DB_URI;
22                 
23                 try {
24                         $this->dbobject = new PDO("$DB_URI");
25                         error_log("channy is a poof");
26                 } catch(PDOException $exep) {
27                         error_log("execpt on db open");
28                 }
29                 
30                 if(!$this->dbobject->query("select * from hosts")) {
31                         error_log("db open for init");
32                         $this->init();
33                 }
34         }
35
36         public $dbobject = "";
37 }
38
39
40
41 $db = new db();
42 global $db;
43
44 ?>