Add sqlite approach
[matches/MCTX3420.git] / testing / sqlite-approach / www / sqlite.php
1 <?php
2         class MyDB extends SQLite3
3         {
4                 function __construct()
5                 {
6                         $this->open('../db/data.db');
7                 }
8
9                 function getSensorValue($id)
10                 {
11                         //needs error checking, but you get the idea
12                         $ret = $this->query("select value from sensors where sensor_id={$id}");
13                         $row = $ret->fetchArray(SQLITE3_NUM);
14                         return $row[0];
15                 }
16         }
17
18         $db = new MyDB();
19         if (!$db) {
20                 echo $db->lastErrorMsg();
21         } else {
22                 echo "yay<br>\n";
23         }
24
25         $ret = $db->query('SELECT * from test');
26         while ($row = $ret->fetchArray(SQLITE3_ASSOC)) {
27                 echo "NUM = ". $row['num'] . "<br>\n";
28         }
29
30         echo "Sensor 1 value: " . $db->getSensorValue(1). "<br>\n";
31         $db->close();
32
33 ?>

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