-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnect_db.php
37 lines (30 loc) · 896 Bytes
/
connect_db.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
$dbtype='pgsql';
include('dbconn.php');
// sets the values username, server, database and password
try{
$connectstring=$dbtype.':host='.$server.';dbname='.$database;
$dbh = new PDO($connectstring, $username, $password);
if($dbtype=='pgsql'){
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
}
catch(PDOException $e){
$message=$e->getMessage();
exit( "<p>Cannot connect - $message</p>");
}
function voltagelevel(){
global $dbh;
$sql="select min(value) from lastmeas_complete where unit='V'";
$qry=$dbh->prepare($sql);
$qry->execute();
$value=$qry->fetchAll(PDO::FETCH_ASSOC)[0]['min'];
return(levelclass($value));
}
function levelclass($value){
$vstatus='critical'; $color='red';
if($value > 3.4){$vstatus='low'; $color='yellow';}
if($value > 3.6){$vstatus='OK'; $color='green';}
return($vstatus);
}
?>