diff --git a/dev_mvc/model/testactions/model_createdb.php b/dev_mvc/model/testactions/model_createdb.php index cc588d4..73b1300 100644 --- a/dev_mvc/model/testactions/model_createdb.php +++ b/dev_mvc/model/testactions/model_createdb.php @@ -62,27 +62,27 @@ function createDB(){ `active` tinyint(1) DEFAULT '0', PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=latin1"); - echol("created table $table"); - } - //table exists - else{ - echol("table $table already exists, skipping"); - } + echol("created table $table"); + } + //table exists + else{ + echol("table $table already exists, skipping"); + } - $table = 'usersessions'; - $query = $con->query("SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '$table'"); - if($query->fetchColumn() != 4){ - echol('table doesnt exist'); - $query = $con->query( - " CREATE TABLE `usersessions` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `uid` int(11) NOT NULL, - `token` varchar(256) NOT NULL, - `expires` datetime NOT NULL, - PRIMARY KEY (`id`) - ) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=latin1"); - echol("created table $table"); - } + $table = 'usersessions'; + $query = $con->query("SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = '$table'"); + if($query->fetchColumn() != 4){ + echol('table doesnt exist'); + $query = $con->query( + " CREATE TABLE `usersessions` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `uid` int(11) NOT NULL, + `token` varchar(256) NOT NULL, + `expires` datetime NOT NULL, + PRIMARY KEY (`id`) + ) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=latin1"); + echol("created table $table"); + } //table exists else{ echol("table $table already exists, skipping"); @@ -99,7 +99,7 @@ function createDB(){ `activationkey` varchar(256) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1"); - echol("created table $table"); + echol("created table $table"); } //table exists else{ @@ -118,7 +118,7 @@ function createDB(){ `permLevel` int(16) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1"); - echol("created table $table"); + echol("created table $table"); } //table exists else{ @@ -140,7 +140,7 @@ function createDB(){ `date_created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1"); - echol("created table $table"); + echol("created table $table"); } //table exists else{ @@ -160,7 +160,7 @@ function createDB(){ `date_created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1"); - echol("created table $table"); + echol("created table $table"); } //table exists else{ diff --git a/dev_mvc/model/testactions/model_populatedb.php b/dev_mvc/model/testactions/model_populatedb.php new file mode 100644 index 0000000..6cbf97e --- /dev/null +++ b/dev_mvc/model/testactions/model_populatedb.php @@ -0,0 +1,54 @@ +query("SELECT COUNT(*) FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '$db'"); + //db exists + if($query->fetchColumn() != 1){ + $query = $con->query("CREATE DATABASE $db"); + echol('db doesnt exist'); + } + //db doesn't exist + else{ + echol('db already exists, skipping'); + } + //select db + $con->exec("USE $db"); + //test if table exists + + + + echol('table doesnt exist'); + $query = $con->query("INSERT INTO `users` + (`ID`, `username`, `email`, `password`, `reg_ip`, `permissions`, `active`) + VALUES + (NULL, 'Andreas', 'the.hion.v@gmail.com', 'huts', '::1', '-1', '1')"); + $query = $con->query("INSERT INTO `users` + (`ID`, `username`, `email`, `password`, `reg_ip`, `permissions`, `active`) + VALUES + (NULL, 'Bram', 'bram@gmail.com', 'huts', '::1', '-1', '1')"); + echol("created test users"); + } + catch(PDOException $e){ + die("pdo exception, cannot connect to sql:
$e"); + } +} \ No newline at end of file