From: Jeremy Tan Date: Tue, 13 Aug 2013 11:23:30 +0000 (+0800) Subject: Add sqlite approach X-Git-Url: https://git.ucc.asn.au/?p=matches%2FMCTX3420.git;a=commitdiff_plain;h=3f54b5dbd005f27826447fda9b732825d0ce3e77 Add sqlite approach --- diff --git a/notes/a.txt b/notes/a.txt deleted file mode 100644 index e69de29..0000000 diff --git a/testing/sqlite-approach/README.txt b/testing/sqlite-approach/README.txt new file mode 100644 index 0000000..b7d3e9c --- /dev/null +++ b/testing/sqlite-approach/README.txt @@ -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 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 index 0000000..bd8496e --- /dev/null +++ b/testing/sqlite-approach/www/sqlite.php @@ -0,0 +1,33 @@ +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
\n"; + } + + $ret = $db->query('SELECT * from test'); + while ($row = $ret->fetchArray(SQLITE3_ASSOC)) { + echo "NUM = ". $row['num'] . "
\n"; + } + + echo "Sensor 1 value: " . $db->getSensorValue(1). "
\n"; + $db->close(); + +?> \ No newline at end of file