· 7 years ago · Mar 01, 2019, 11:18 PM
1$r1 = $this->db->query('SHOW TABLES LIKE 'page'');
2
3
4 // Debbug
5 $r2 = $r1->fetchAll;
6 var_dump ($r2);
7
8 if (count($r1->fetchAll()) > 0 ) {
9
10 echo "The table PAGE exists";
11
12 }
13
14class phase2 {
15
16 function __construct () {
17
18 $dbFile = 'dbconfig.php';
19 $this->dbFile = $dbFile;
20
21 require_once ("$dbFile");
22
23
24 $step = $_GET["step"];
25
26 $username = $DB_USER;
27 $password = $DB_PASS;
28 $server = $DB_SERVER;
29 $dbName = $DB_NAME;
30
31 $this->step = $step;
32 $this->dbFile = $dbFile;
33 $this->username = $username;
34 $this->password = $password;
35 $this->server = $server;
36 $this->dbName = $dbName;
37
38 $db = new PDO ('mysql:host=' .$server.';dbname='.$this->dbName,$this->username,$this->password);
39
40 $this->db = $db;
41
42 if (empty ($_GET['fot']) ) {
43
44 $fOT = 'false';
45
46 } elseif ($_GET['true']) { $fOT = 'true'; }
47
48 $this->fOT = $fOT;
49
50 $this->IDB = $this->handleDatabase( 1 );
51 $this->IDB2 = $this->handleDatabase( 2 );
52 $this->IDB3 = $this->handleDatabase( 3 );
53
54 }
55
56
57
58public function handleDatabase ($num = 1){
59
60// Prepare SQL Statements
61
62 $IDB1 = $this->db->prepare(
63 "CREATE TABLE pages (
64 id int(11) NOT NULL auto_increment,
65 subject_id int(11) NOT NULL,
66 menu_name varchar(30) NOT NULL,
67 position int(3) NOT NULL,
68 visible tinyint(1) NOT NULL,
69 content text NOT NULL,
70 PRIMARY KEY (id)
71 )ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8");
72
73 $IDB2 = $this->db->prepare("
74 CREATE TABLE subjects (
75 id int(11) NOT NULL auto_increment,
76 menu_name varchar(30) NOT NULL,
77 position int(3) NOT NULL,
78 visible tinyint(1) NOT NULL,
79 PRIMARY KEY (id)
80 )ENGINE=MyISAM AUTO_INCREMENT=6 DEFAULT CHARSET=utf8");
81
82 $IDB3 = $this->db->prepare("
83 CREATE TABLE users (
84 id int(11) NOT NULL auto_increment,
85 username varchar(50) NOT NULL,
86 hashed_password varchar(40) NOT NULL,
87 PRIMARY KEY (id)
88 )ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8");
89
90 $name = "IDB".$num;
91 return isset( $$name)?$$name:false;
92
93}
94//Set Option to True or False
95
96function createTablePages ($fOT){
97
98
99 $r1 = $this->db->query('SHOW TABLES LIKE 'page'');
100
101// Debbug
102 $r2 = $r1->fetchAll;
103 var_dump ($r2);
104
105
106 if (count($r1->fetchAll()) > 0) {
107
108
109 echo "The table PAGE exists";
110
111 } elseif ($fOT == 'true') {
112
113 echo "enteres";
114 $this->IDB1->execute();
115 $this->stepFunction (1,false);
116
117 }
118
119}
120function createTableSubjects ($fOT){
121
122 $r2 = $this->db->query('SHOW TABLES LIKE 'subjects'');
123
124 if (count($r2->fetchAll()) > 0 && $fOT == 'false') {
125
126 echo "The table SUBJECTS exists ";
127
128 } elseif ($fOT == 'true') {
129
130 $this->IDB2->execute();
131 $this->stepFunction (2,false);
132
133 }
134}
135
136function createTableUsers ($fOT){
137
138 $r3 = $this->db->query('SHOW TABLES LIKE 'users'');
139
140 if (count($r3->fetchAll()) > 0 && $fOT == 'false') {
141
142 echo "The table USERS exists";
143
144 } elseif ($fOT == 'true') {
145
146 $this->IDB3->execute();
147 echo "Would you like to populate all the tables?";
148 }
149}
150
151
152public function stepFunction ($fOT,$step){
153
154switch ($step) {
155
156 case 0:
157 $this->createTablePages ($fOT);
158 break;
159 case 1:
160 $this->createTableSubjects($fOT);
161 break;
162 case 2: $this->createTableUsers ($fOT);
163 break;
164 }
165
166
167}
168
169 }
170
171$IDB1 = $this->db->prepare(
172 "CREATE TABLE pages ("
173...
174
175$r1 = $this->db->query('SHOW TABLES LIKE 'page'');
176
177class phase2 {
178
179 function __construct () {
180
181class phase2 {
182
183 public $db;
184
185 function __construct () {