-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.php
More file actions
49 lines (44 loc) · 1.58 KB
/
database.php
File metadata and controls
49 lines (44 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
<?php
function addMovie($title, $rating, $photo, $description, $lengthofmovie) {
$db = new mysqli ("localhost", "root", "", "fresh_tomatos");
$addRowSQL = "INSERT INTO movies(title, rating, photo, description, lengthofmovie) VALUES('" . $db->escape_string($title) . "'," . $rating . ",'" . $db->escape_string($photo) . "','" . $db->escape_string($description) . "'," . $lengthofmovie . ")";
$db->query($addRowSQL);
$db->commit();
$db->close();
}
function removeMovie($title) {
$removeRowSQL = "DELETE FROM movies WHERE title=$title";
$db = new mysqli ("localhost", "root", "", "fresh_tomatos");
$db->query($removeRowSQL);
$db->commit();
$db->close();
}
function editMovie($title, $rating, $photo, $description, $lengthofmovie) {
$editRowSQL = "UPDATE movies WHERE title=$title SET rating=$rating, photo=$photo, description=$description, length=$lengthofmovie";
$db = new mysqli ("localhost", "root", "", "fresh_tomatos");
$db->query($editRowSQL);
$db->commit();
$db->close();
}
function getMovie($title) {
$selectRowsSQL = "SELECT * FROM movies WHERE title=$title";
$db = new mysqli ("localhost", "root", "", "fresh_tomatos");
$mysqli_result = $db->query($selectRowsSQL);
$rows = [];
while ($row = $mysqli_result->fetch_assoc()) {
array_push($rows, $row);
}
$db->close();
return $rows;
}
function selectAllMovies() {
$selectRowsSQL = "SELECT * FROM movies";
$db = new mysqli ("localhost", "root", "", "fresh_tomatos");
$mysqli_result = $db->query($selectRowsSQL);
$rows = [];
while ($row = $mysqli_result->fetch_assoc()) {
array_push($rows, $row);
}
$db->close();
return $rows;
}