-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdo_5_author_repo.php
More file actions
68 lines (42 loc) · 1.58 KB
/
pdo_5_author_repo.php
File metadata and controls
68 lines (42 loc) · 1.58 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
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
<?php
include_once 'IRepo.php';
$h = require 'pubs_connect.php';
class authorRepo implements IRepository{
private $handle;
public function __construct($handle)
{
$this->handle = $handle;
}
//public function __destruct() {
// $handle = null;
// }
public function add($item){}
public function find($id){
$sql = 'SELECT * FROM authors WHERE au_id = :auid';
$stmt = $this->handle->prepare($sql);
$stmt->bindParam(':auid', $id, PDO::PARAM_STR);
$stmt->execute();
// FETCH_ASSOC = index by column name
$author = $stmt->fetchAll(PDO::FETCH_ASSOC)[0]; // get array
return $author;
}
public function findAll(){
$sql = 'SELECT * FROM authors';
$stmt = $this->handle->query($sql);
$authors = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $authors;
}
public function update($item){
require_once 'model.php';
$sql = 'UPDATE authors SET au_fname= :aufname, au_lname= :aulname, phone= :aunumber, address= :auaddress WHERE au_id= :auid';
$stmt = $this->handle->prepare($sql);
$stmt->bindParam(':auid', $item->id, PDO::PARAM_STR);
$stmt->bindParam(':aufname', $item->fname, PDO::PARAM_STR);
$stmt->bindParam(':aulname', $item->lname, PDO::PARAM_STR);
$stmt->bindParam(':aunumber', $item->number, PDO::PARAM_STR);
$stmt->bindParam(':auaddress', $item->address, PDO::PARAM_STR);
$stmt->execute();
}
public function remove($id){}
}
?>