Add sqlite approach
authorJeremy Tan <[email protected]>
Tue, 13 Aug 2013 11:23:30 +0000 (19:23 +0800)
committerJeremy Tan <[email protected]>
Tue, 13 Aug 2013 11:23:30 +0000 (19:23 +0800)
notes/a.txt [deleted file]
testing/sqlite-approach/README.txt [new file with mode: 0644]
testing/sqlite-approach/db/data.db [new file with mode: 0644]
testing/sqlite-approach/www/sqlite.php [new file with mode: 0644]

diff --git a/notes/a.txt b/notes/a.txt
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/testing/sqlite-approach/README.txt b/testing/sqlite-approach/README.txt
new file mode 100644 (file)
index 0000000..b7d3e9c
--- /dev/null
@@ -0,0 +1,12 @@
+SQLite approach to interfacing with web frontend:
+
+*Main program reads in sensor data and updates the sqlite database 
+ with this new data
+*When sqlite.php is called, the database is queried, and the values returned
+ to the caller (format can be anything you like)
+*You could have a main webpage, ie index.html
+*Whenever you need to update the page, you use jQuery (or other method)
+ to call sqlite.php, which returns the data needed
+
+This works because SQLite allows concurrent access to the database
+(or it should).
\ No newline at end of file
diff --git a/testing/sqlite-approach/db/data.db b/testing/sqlite-approach/db/data.db
new file mode 100644 (file)
index 0000000..4d7095b
Binary files /dev/null and b/testing/sqlite-approach/db/data.db differ
diff --git a/testing/sqlite-approach/www/sqlite.php b/testing/sqlite-approach/www/sqlite.php
new file mode 100644 (file)
index 0000000..bd8496e
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+       class MyDB extends SQLite3
+       {
+               function __construct()
+               {
+                       $this->open('../db/data.db');
+               }
+
+               function getSensorValue($id)
+               {
+                       //needs error checking, but you get the idea
+                       $ret = $this->query("select value from sensors where sensor_id={$id}");
+                       $row = $ret->fetchArray(SQLITE3_NUM);
+                       return $row[0];
+               }
+       }
+
+       $db = new MyDB();
+       if (!$db) {
+               echo $db->lastErrorMsg();
+       } else {
+               echo "yay<br>\n";
+       }
+
+       $ret = $db->query('SELECT * from test');
+       while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
+               echo "NUM = ". $row['num'] . "<br>\n";
+       }
+
+       echo "Sensor 1 value: " . $db->getSensorValue(1). "<br>\n";
+       $db->close();
+
+?>
\ No newline at end of file

UCC git Repository :: git.ucc.asn.au