-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.php
More file actions
69 lines (62 loc) · 2.4 KB
/
page.php
File metadata and controls
69 lines (62 loc) · 2.4 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
69
<?php
/**
* Page Name: page.php
* Author: Rutul Patel
* Student Number: 200335158
* Description of Page: This is a controllers and all the functions for CMS
*/
include_once("Config/database.php"); // config database
function _executeAndClose($statement)
{
$statement->execute(); // run on the db server
$statement->closeCursor(); // close the connection
}
function CreatePage($pageTitle, $pageContent) // function for creating page and insert value into database
{
$db = DBConnection();
$query = "INSERT INTO pages (title, content) VALUES (:page_title, :page_content)"; //SQL Query for database
$statement = $db->prepare($query); // encapsulate the sql statement
$statement->bindValue(':page_title', $pageTitle);
$statement->bindValue(':page_content', $pageContent);
_executeAndClose($statement);
}
function ReadPages()// function for selecting and page confirmation
{
$db = DBConnection();
$query = "SELECT * FROM pages"; // SQL statement
$statement = $db->prepare($query); // encapsulate the sql statement
$statement->execute(); // run on the db server
$pages = $statement->fetchAll(); // returns an array
$statement->closeCursor(); // close the connection
return $pages;
}
function UpdatePage($pageID, $pageTitle, $pageContent) // function for updatePage
{
$db = DBConnection();
$query = "UPDATE pages SET title = :page_title, content = :page_content WHERE id = :page_id "; // SQL Query statement
$statement = $db->prepare($query); // encapsulate the sql statement
$statement->bindValue(':page_id', $pageID);
$statement->bindValue(':page_title', $pageTitle);
$statement->bindValue(':page_content', $pageContent);
_executeAndClose($statement);
}
function GetPageById($pageId) // function for identifying page from id
{
$db = DBConnection(); // Database Connection
$query = "SELECT * FROM pages WHERE id = :page_id "; // SQL statement
$statement = $db->prepare($query); // encapsulate the sql statement
$statement->bindValue(':page_id', $pageId);
$statement->execute(); // run on the db server
$page = $statement->fetch(); // returns only one record
$statement->closeCursor(); // close the connection
return $page;
}
function DeletePage($pageId) // function for the Deleting page with use functionId
{
$db = DBConnection(); // Database Connection
$query = "DELETE FROM pages WHERE id = :page_id ";
$statement = $db->prepare($query);
$statement->bindValue(":page_id", $pageId);
_executeAndClose($statement);
}
?>