Stap 5: Code-webtoepassing
Nu dit de code is die inferface de webtoepassing met Intel Edison bord:
$mysqli = nieuwe mysqli ("localhost", "root", "", "mypet");
Temperatuur $query = "SELECT stabilimento uit 'temperatura' ORDER BY id DESC limiet 1";
$stmt = $mysqli -> prepare($query); $stmt -> execute();
$stmt -> bind_result($temp);
terwijl ($stmt -> {fetch())}
Gas $query = "SELECT stabilimento uit 'gas' ORDER BY id DESC limiet 1";
$stmt = $mysqli -> prepare($query); $stmt -> execute();
$stmt -> bind_result($gas);
terwijl ($stmt -> {fetch())}
Brand $query = "SELECT stabilimento uit 'fuoco' ORDER BY id DESC limiet 1";
$stmt = $mysqli -> prepare($query); $stmt -> execute();
$stmt -> bind_result($fire);
terwijl ($stmt -> {fetch())}
Vochtigheid $query = "SELECT stabilimento uit 'umidita' ORDER BY id DESC limiet 1";
$stmt = $mysqli -> prepare($query); $stmt -> execute();
$stmt -> bind_result($humidity);
terwijl ($stmt -> {fetch())}
$mysqli -> close();? >
Aan het eind is dit de code die kan toestaan ons te lezen van de laatste waarde die leesbaar zijn door de Intel Edison:
if(isset($_Get['temperatura']) & & isset($_GET['gas']) & & isset($_GET['umidita']) & & isset($_GET['fuoco'])) {$temperatura = $_GET ['temperatura']; $gas = $_GET ['gas']; $umidita = $_GET ['umidita']; $fuoco = $_GET ['fuoco']; $link = mysql_connect ('localhost', 'root', ''); als (! $link) {sterven ('Impossibile connettersi: '. mysql_error());} mysql_select_db("mypet") of sterven ("Impossibile selezionare il database.");
Opvragen van 1 $sql = "INSERT INTO temperatura (stabilimento) VALUES ('. $temperatura."); "; $retval = mysql_query ($sql, $link); if(! $RetVal) {sterven ('Impossibile eseguire la query: 1'. mysql_error());}
Query 2 $sql = "INSERT INTO gas (stabilimento) VALUES ('. $gas."); "; $retval = mysql_query ($sql, $link); if(! $RetVal) {sterven ('Impossibile eseguire la query: 2'. mysql_error());}
Opvragen van 1 $sql = "INSERT INTO umidita (stabilimento) VALUES ('. $umidita."); "; $retval = mysql_query ($sql, $link); if(! $RetVal) {sterven ('Impossibile eseguire la query: 3'. mysql_error());}
Opvragen van 1 $sql = "INSERT INTO fuoco (stabilimento) VALUES ('. $fuoco."); "; $retval = mysql_query ($sql, $link); if(! $RetVal) {sterven ('Impossibile eseguire la query: 1'. mysql_error());}
mysql_close($link); }
? >
?>