-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodel.php
55 lines (42 loc) · 1.79 KB
/
model.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
<?php
$host = "localhost";
$dbName = "vue";
$username = "root";
$password= "";
try {
$conn = new PDO("mysql:host=$host; dbname = $dbName", $username, $password);
}catch(PDOException $e) {
die("DB connect error: " . $e->getMessage());
}
$dataReceived = json_decode(file_get_contents("php://input"));
if($dataReceived->action == 'fetchall') {
$query = "SELECT * FROM etudiant";
$statement = $conn->query($query);
$data = $statement->fetchAll(PDO::FETCH_ASSOC);
print(json_encode($data));
}
else if($dataReceived->action == 'insert') {
$numEt = $dataReceived->numEt;
$nom = $dataReceived->nom;
$note_math = $dataReceived->note_math;
$note_phys = $dataReceived->note_phys;
$query = "INSERT INTO etudiant (numEt, nom, note_math, note_phys) VALUES (?, ?, ?, ?)";
$statement = $conn->prepare($query);
$statement->execute([$numEt, $nom, $note_math, $note_phys]);
}
else if($dataReceived->action == 'update') {
$ancientNum = $dataReceived->$ancientNum;
$numEt = $dataReceived->numEt;
$nom = $dataReceived->nom;
$note_math = $dataReceived->note_math;
$note_phys = $dataReceived->note_phys;
$statement = $conn->prepare($query);
$query = "UPDATE etudiant SET numEt=?, nom=?, note_math=?, note_phys=? WHERE numEt=?";
$statement->execute([$numEt, $nom, $note_math, $note_phys, $ancientNum]);
}
else if($dataReceived->action == 'delete') {
$numEt = $dataReceived->numEt;
$query = "DELETE FROM etudiant WHERE numEt = ?";
$statement = $conn->prepare($query);
$statement->execute([$numEt]);
}