传感器数据输入输出
输入in.php:
<?php
$wen=$_REQUEST["wen"];
$shi=$_REQUEST["shi"];
$ttt=$_REQUEST["time"];
$dsn = 'sqlite:/usr/share/nginx/www/pi';
try{
$dbh = new pdo($dsn,$user,$password);
//echo 'PDO Connection OK!'.'<br>';
//$dbh->exec("INSERT INTO info values(null,33,33,'2011-1-1 11:11:0')");
$dbh->exec("INSERT INTO info values(null,$wen,$shi,'$ttt')");
echo 'local ok';
//$dbh->beginTransaction();
//$sth = $dbh->prepare('SELECT *FROM info');
//$sth->execute();
//$result = $sth->fetchAll();
//print_r($result);
$dsn = null;
}catch (pdoexception $e){
echo 'Connection failed:'.$e->getmessage();
$dsn = null;
}
?>
输出disp.php:
<?php
require_once './SVGGraph/SVGGraph.php';
$graph = new SVGGraph(500, 400,array (
//'grid_division_h' => 1, // 1 date per year
//'grid_division_v' => 1
));
$dsn = 'sqlite:/usr/share/nginx/www/pi';
try{
$dbh = new pdo($dsn,$user,$password);
$dbh->beginTransaction();
$sth = $dbh->prepare('SELECT wen FROM info order by num desc limit 50');
$sth->execute();
$result = $sth->fetchAll();
print_r($result);
$recordlist=array();
$ii=0;
foreach($result as $row){
$recordlist[$ii]=$row[0];
$ii++;
}
print_r($recordlist);
$dsn = null;
}catch (pdoexception $e){
echo 'Connection failed:'.$e->getmessage();
$dsn = null;
}
$graph->Values($recordlist);
$graph->Render('LineGraph');
?>
发表评论