-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather.class.inc.php
52 lines (49 loc) · 1.85 KB
/
weather.class.inc.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
class weather{
private $pdo;
public $id;
public $date;
public $time;
public $location;
public $weather;
public $description;
public $temp;
public $temp_min;
public $temp_max;
public function __construct( $pdo ){
$this->pdo = $pdo;
}
public function getWeather( $location, $date ){
$sql = "SELECT * FROM `weather` WHERE `location`=:locationX AND `date`=:dateX LIMIT 1";
$stmt = $this->pdo->prepare( $sql );
$stmt->bindParam(':locationX', $location, PDO::PARAM_STR);
$stmt->bindParam(':dateX', $date, PDO::PARAM_STR);
$stmt->execute();
if( $stmt->rowCount() ){
$row = $stmt->fetchObject();
return $row;
}
return false;
}
public function setWeather( $date, $time, $location, $weather, $description, $temp, $temp_min, $temp_max ){
// check if data already exists
if( !$this->getWeather($location, $date) ){
$sql = "INSERT INTO `weather` (`date`, `time`, `location`, `weather`, `description`, temp, `temp_min`, `temp_max`) VALUES (:dateX, :timeX, :locationX, :weatherX, :descriptionX, :tempX, :temp_minX, :temp_maxX)";
$stmt = $this->pdo->prepare( $sql );
$stmt->bindParam(':dateX', $date, PDO::PARAM_STR);
$stmt->bindParam(':timeX', $time, PDO::PARAM_STR);
$stmt->bindParam(':locationX', $location, PDO::PARAM_STR);
$stmt->bindParam(':weatherX', $weather, PDO::PARAM_STR);
$stmt->bindParam(':descriptionX', $description, PDO::PARAM_STR);
$stmt->bindParam(':tempX', $temp, PDO::PARAM_STR);
$stmt->bindParam(':temp_minX', $temp_min, PDO::PARAM_STR);
$stmt->bindParam(':temp_maxX', $temp_max, PDO::PARAM_STR);
$stmt->execute();
if( $stmt->rowCount() ){
return $this->pdo->lastInsertId();
}
return false;
}
}
}
?>