-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rate.php
41 lines (30 loc) · 1.05 KB
/
Rate.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
<?php
class Rate extends Model
{
public static function getRateByDate($date)
{
$db = Db::getConnection();
$exchangeRate = array();
$sql = "SELECT USD, EUR FROM exchange_rate WHERE date=STR_TO_DATE(:date, '%Y-%m-%d')";
$result = $db->prepare($sql);
$result->bindParam(':date', $date, PDO::PARAM_STR);
$result->execute();
$i = 0;
while ($row = $result->fetch()) {
$exchangeRate['USD'] = $row['USD'];
$exchangeRate['EUR'] = $row['EUR'];
$i++;
}
return $exchangeRate;
}
public static function addRateByDate($USD, $EUR, $date)
{
$db = Db::getConnection();
$sql = "INSERT INTO exchange_rate (USD, EUR, date) VALUES (:USD, :EUR, STR_TO_DATE(:date, '%Y-%m-%d'))";
$result = $db->prepare($sql);
$result->bindParam(':USD', $USD, PDO::PARAM_STR);
$result->bindParam(':EUR', $EUR, PDO::PARAM_STR);
$result->bindParam(':date', $date, PDO::PARAM_STR);
return $result->execute();
}
}