summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHorus32014-02-25 18:57:34 +0100
committerHorus32014-02-25 18:57:34 +0100
commit4baee1f0a462bf9d3a7210f4c1ca44ca9c705da9 (patch)
tree0ff7128f3fd46004918d3d8cefd7d572e2938b8d
parent0e7bf4852888e06ec2da9b83aabcc8b39475d15b (diff)
downloadrandom-4baee1f0a462bf9d3a7210f4c1ca44ca9c705da9.tar.gz
database setup
-rw-r--r--www/insertfile.php29
-rw-r--r--www/setup.php34
2 files changed, 59 insertions, 4 deletions
diff --git a/www/insertfile.php b/www/insertfile.php
index cfc52a7..5e07130 100644
--- a/www/insertfile.php
+++ b/www/insertfile.php
@@ -1,10 +1,31 @@
<?
-$en_dic = "../blob/en_GB.dic";
-$test = "../blob/test";
+$dic = "../blob/en_GB.dic";
+$table = "english";
+
+$bool = false;
+
+$db = new SQLite3("../database/dict.db");
+
+if($file = file($dic)){
+
+ $rows = count($file);
+ for($i=0;$i<$rows;$i++){
+ if(!$db->exec("
+ BEGIN TRANSACTION;
+ INSERT INTO " . $table " VALUES (NULL, " . $file[$i] . ");
+ COMMIT;
+ ")){
+ echo "Failure writing to the database at row" . $i ."!";
+ $bool = true;
+ break;
+ }
+ }
+
+ if(!$bool){
+ echo "Successfull transfered the file into the database.";
+ }
-if($file = file($en_dic)){
- echo "Inserted file";
} else {
echo "No file found!";
}
diff --git a/www/setup.php b/www/setup.php
new file mode 100644
index 0000000..a4ab123
--- /dev/null
+++ b/www/setup.php
@@ -0,0 +1,34 @@
+<?
+
+$db = new SQLite3("../database/dict.db");
+
+foreach ($_GET as $name => $value) {
+ if(preg_match("/drop(ped)?/i",$name)){
+ $bool=true;
+ }
+}
+
+if($bool){
+ if($db->exec("
+ BEGIN TRANSACTION;
+ PRAGMA writable_schema = 1;
+ DELETE FROM sqlite_master WHERE type = 'table';
+ PRAGMA writable_schema = 0;
+ COMMIT;
+ VACUUM;")
+ ){
+ echo "dropped everything";
+ } else {
+ echo "error with database";
+ }
+} else {
+ if($db->exec("
+ BEGIN TRANSACTION;
+ CREATE TABLE IF NOT EXISTS english (id INTEGER PRIMARY KEY, word TEXT UIQUE);
+ COMMIT;")
+ ) {
+ echo "Success!";
+ } else {
+ echo "Failure!" ;
+ }
+}