-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
72 lines (55 loc) · 2.1 KB
/
functions.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
//Loome ühenduse andmebaasiga
require_once("../config_global.php");
$database = "if15_earis_3";
function getCarData(){
$mysqli = new mysqli($GLOBALS["servername"], $GLOBALS["server_username"], $GLOBALS["server_password"], $GLOBALS["database"]);
$stmt = $mysqli->prepare("SELECT id, user_id, number_plate, color FROM car_plates WHERE deleted IS NULL");
$stmt->bind_result($id, $user_id, $number_plate, $color);
$stmt->execute();
//tekitan tühja massiivi, kus edaspidi hoian objekte
$car_array = array ();
//tee midagi seni, kuni saame andmebaasist ühe rea andmeid
while($stmt->fetch()){
//seda siin sees tehakse nii mitu korda kui on ridu
//tekitan objekti, kus hakkan hoidma väärtusi
$car = new StdClass();
$car->id = $id;
$car->plate =$number_plate;
$car->user_id=$user_id;
$car->color=$color;
//lisan massiivi ühe rea juurde
array_push($car_array, $car);
//var dump ütleb muutuja tüübi ja sisu
//echo "<pre>";
//var_dump($car_array);
//echo "</pre><br>";
}
//tagastan massiivi, kus kõik read sees
return $car_array;
$stmt->close();
$mysqli->close();
}
function deleteCar($id){
$mysqli = new mysqli($GLOBALS["servername"], $GLOBALS["server_username"], $GLOBALS["server_password"], $GLOBALS["database"]);
$stmt = $mysqli->prepare("UPDATE car_plates SET deleted=NOW() WHERE id=?");
$stmt->bind_param("i", $id);
if($stmt->execute()){
//sai kustutatud, kustutame aadressirea tühjaks
header("Location: table.php");
}
$stmt->close();
$mysqli->close();
}
function updateCar($id, $number_plate, $color){
$mysqli = new mysqli($GLOBALS["servername"], $GLOBALS["server_username"], $GLOBALS["server_password"], $GLOBALS["database"]);
$stmt = $mysqli->prepare("UPDATE car_plates SET number_plate=?, color=? WHERE id=?");
$stmt->bind_param("ssi", $number_plate, $color, $id);
if($stmt->execute()){
//sai kustutatud, kustutame aadressirea tühjaks
//header("Location: table.php");
}
$stmt->close();
$mysqli->close();
}
?>