From 3f54b5dbd005f27826447fda9b732825d0ce3e77 Mon Sep 17 00:00:00 2001 From: Jeremy Tan Date: Tue, 13 Aug 2013 19:23:30 +0800 Subject: [PATCH] Add sqlite approach --- notes/a.txt | 0 testing/sqlite-approach/README.txt | 12 +++++++++ testing/sqlite-approach/db/data.db | Bin 0 -> 3072 bytes testing/sqlite-approach/www/sqlite.php | 33 +++++++++++++++++++++++++ 4 files changed, 45 insertions(+) delete mode 100644 notes/a.txt create mode 100644 testing/sqlite-approach/README.txt create mode 100644 testing/sqlite-approach/db/data.db create mode 100644 testing/sqlite-approach/www/sqlite.php 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 0000000000000000000000000000000000000000..4d7095bc9e04ddb26e203f9218b6382d8d3ac912 GIT binary patch literal 3072 zcmWFz^vNtqRY=P(%1ta$FlJz3U}R))P*7lCVBi8`W*~+E79azJVSo|Fz(aE}=sr^C z1u9@-Zf0OU2P8(pXb6mk0CEU;GO>wEOEYGdBqrsg7N_PF=NA=2DQ4#&SH}=ng%C$4 zA6Esapn?X35ucf&keOGaqfnNZQ<@55Y8o)IiHnLdx`K@=Ni8k`VI~wqKq3kn3VEfu zU>%^m$;|wPf%y;f4open('../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 -- 2.20.1