-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel_db.php
More file actions
34 lines (31 loc) · 1.18 KB
/
model_db.php
File metadata and controls
34 lines (31 loc) · 1.18 KB
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
<?php
class Database{
private $host = "mysql:dbname=crud_ajax";
private $user = "root";
private $password = "";
private function getconnexion(){
try {
return new PDO($this->host, $this->user, $this->password);
} catch (PDOException $e) {
die('Erreur:' . $e->getMessage());
}
}
public function create(string $customer, string $cashier, int $amount, int $received, int $returned, string $state)
{
$q = $this->getconnexion()->prepare("INSERT INTO facture (customer, cashier, amount, received, returned, state) VALUES (:customer, :cashier, :amount, :received, :returned, :state)");
return $q->execute([
'customer' => $customer,
'cashier' => $cashier,
'amount' => $amount,
'received' => $received,
'returned' => $returned,
'state' => $state,
]);
}
public function read(){
return $this->getconnexion()->query("SELECT * FROM facture ORDER BY id")->fetchAll(PDO::FETCH_OBJ);
}
public function countFacture() {
return (int)$this->getconnexion()->query("SELECT COUNT(id) as count FROM facture")->fetch()[0];
}
}