prepare($sql); $sth->execute(); // Fetch all of the remaining rows in the result set * / $result = $sth->fetchAll(PDO::FETCH_ASSOC); // ** close the database connection *** / $dbh = null; } catch(PDOException $e) { echo $e->getMessage(); } $json_data = json_encode($result); return $json_data; } function getJSON_Data1($sq) { global $hostname; global $username; global $password; global $dbname; global $sql; try { $dbh = new PDO("mysql:host=$hostname;dbname=$dbname", $username, $password); // *** The SQL SELECT statement *** / $sth = $dbh->prepare($sq); //$sth = $dbh->prepare("SELECT `temperatur`, `luftdruck`,`luftfeuchtigkeit`, `zeit` FROM `wetter` order by `zeit`"); $sth->execute(); // Fetch all of the remaining rows in the result set * / $result = $sth->fetchAll(PDO::FETCH_ASSOC); // ** close the database connection *** / $dbh = null; } catch(PDOException $e) { echo $e->getMessage(); } $json_data = json_encode($result); return $json_data; } function doQuery($sql) { global $hostname; global $username; global $password; global $dbname; $link = mysqli_connect($hostname, $username, $password, $dbname); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } if ($result = mysqli_query($link, $sql)) { return $result; } else return null; } function getLastTime() { global $sqlTime; $zeit = ""; $result = doQuery($sqlTime); if ($result != null) { $obj = mysqli_fetch_object($result); $zeit = $obj->time; } mysqli_free_result($result); // free result set return $zeit; } function getAktuelleWerte($dauer) { global $sql1; global $sql2; global $sql2a; $html = ""; $zeit = ""; // aktuelle Zeit $tA = ""; // aktuelle Temperatur $pA = ""; $hA = ""; // result hat max. 1 Wert $result = doQuery($sql1); $dauer = $dauer / 72; if ($dauer == 1) $dauer .= " Tag"; else $dauer .= " Tage"; if ($result != null) { //while ($obj = mysqli_fetch_object($result)) { $obj = mysqli_fetch_object($result); $zeit = $obj->time; $tA = $obj->temperature; $pA = $obj->pressure; $hA = $obj->humidity; } mysqli_free_result($result); // free result set // Mittelwerte -- max. 1 Ergebniszeile $result1 = doQuery($sql2a); if ($result1 != null) { $obj = mysqli_fetch_object($result1); $avgT = $obj->avgT; $avgP = $obj->avgP; $avgH = $obj->avgH; } mysqli_free_result($result); // free result set // jetzt min-max-Werte $tmin = 100; $tmax = -100; // Temperatur $pmin = 2000; $pmax = 0; // Luftdruck $lmin = 100; $lmax = 0; // Luftfeuchtigkeit $result = doQuery($sql2); if ($result != null) { while ($obj = mysqli_fetch_object($result)) { if ($obj->temperature < $tmin) $tmin = $obj->temperature; if ($obj->temperature > $tmax) $tmax = $obj->temperature; if ($obj->pressure < $pmin) $pmin = $obj->pressure; if ($obj->pressure > $pmax) $pmax = $obj->pressure; if ($obj->humidity < $lmin) $lmin = $obj->humidity; if ($obj->humidity > $lmax) $lmax = $obj->humidity; } mysqli_free_result($result); // free result set } $html = "

letzter Messwert um   $zeit"; $html .= "  ·   Zeitraum: $dauer

"; $html = "
°C
"; $html .= sprintf("
T = %6.2f °C
",$tA); $html .= sprintf("
min = %6.2f °C
",$tmin); $html .= sprintf("
max = %6.2f °C
",$tmax); $html .= sprintf("
avg = %6.2f °C
",$avgT); $html .= "
"; $html .= "
Pa
"; $html .= sprintf("
p = %6.2f hPa
",$pA); $html .= sprintf("
min = %6.2f hPa
",$pmin); $html .= sprintf("
max = %6.2f hPa
",$pmax); $html .= sprintf("
avg = %6.2f hPa
",$avgP); $html .= "
"; $html .= "
%
"; $html .= sprintf("
h = %6.2f %
",$hA); $html .= sprintf("
min = %6.1f %
",$lmin); $html .= sprintf("
max = %6.1f %
",$lmax); $html .= sprintf("
avg = %6.1f %
",$avgH); $html .= "
"; $html .= "
"; mysqli_close($link); // close connection return $html; } function getDaten() { global $sql2; $html = ""; $result = doQuery($sql2); $html .= "
";
    $html .= sprintf ("%-20s   %-8s  %-10s      %-5s (%) \n", "Zeit", "Temperatur","Luftdruck","Luftfeuchtigkeit");
    $html .=  "-----------------------------------------------------------------------\n";
    if ($result != null) {
        while ($obj = mysqli_fetch_object($result)) {
            $html .= sprintf ("%s   %6.2f °C   %8.2f hPa  %5d % \n", $obj->time, $obj->temperature, $obj->pressure, $obj->humidity);
        }
        mysqli_free_result($result);  // free result set
    } else { $html .=  "NO - error bei query";}
    $html .=  "
"; mysqli_close($link); // close connection return $html; } ?>