-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.php
37 lines (32 loc) · 1.15 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
<?php
class database{
var $host = 'localhost';
var $port = '5432';
var $dbname = 'crud';
var $user = 'postgres';
var $password = 'admin';
function __construct(){
pg_connect("host=$this->host port = $this->port dbname = $this->dbname user = $this->user password = $this->password");
}
function select(){
$query = "SELECT * FROM book ORDER BY book_id";
$result = pg_query($query);
while ($row = pg_fetch_row($result)){
$data[] = $row;
}
return $data;
}
function insert($book_name, $author, $publisher, $date_published, $price){
$query = "INSERT INTO book VALUES (DEFAULT, '$book_name', '$author', '$publisher', '$date_published', '$price')";
pg_query($query);
}
function update($book_id, $book_name, $author, $publisher, $date_published, $price){
$query = "UPDATE book SET book_name = '$book_name', author = '$author', publisher = '$publisher', date_published = '$date_published', price = '$price' WHERE book_id = '$book_id'";
pg_query($query);
}
function delete($book_id){
$query = "DELETE FROM book WHERE book_id = '$book_id'";
pg_query($query);
}
}
?>