This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.php
76 lines (74 loc) · 2.48 KB
/
db.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
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
70
71
72
73
74
75
76
<?php
require('fpdf/fpdf.php');
$servername='localhost';
$username='root';
$password='';
$dbname = "zora";
$conn=mysqli_connect($servername,$username,$password, $dbname);
if(!$conn){
die('Could not Connect MySql Server:' .mysql_error());
}
try {
$pdo = new PDO("mysql:host=" . $servername . ";dbname=" . $dbname, $username, $password);
// Set the PDO error mode to exception
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
// Display the connection error message
die("Connection failed: " . $e->getMessage());
}
// Create a function to get all the courses from the database
function get_courses($pdo) {
// Prepare the SQL statement to select all the courses
$stmt = $pdo->prepare("SELECT * FROM courses");
// Execute the statement
$stmt->execute();
// Fetch all the results as an associative array
$courses = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Return the courses array
return $courses;
}
function get_ucourses($pdo ,$email) {
// Prepare the SQL statement to select all the courses
$stmt = $pdo->prepare("SELECT * FROM orders WHERE email = $email");
// Execute the statement
$stmt->execute();
// Fetch all the results as an associative array
$courses = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Return the courses array
return $courses;
}
// Create a function to get a single course by its id from the database
function get_course($pdo, $id) {
// Prepare the SQL statement to select the course by its id
$stmt = $pdo->prepare("SELECT * FROM courses WHERE id = :id");
// Bind the id parameter to the statement
$stmt->bindParam(':id', $id);
// Execute the statement
$stmt->execute();
// Fetch the result as an associative array
$course = $stmt->fetch(PDO::FETCH_ASSOC);
// Return the course array
return $course;
}
// Define the get_item function
function get_item ($pdo, $id) {
// Prepare the SQL statement to get the item data by its id
$stmt = $pdo->prepare("SELECT * FROM orders WHERE order_id = :id");
// Bind the id to the statement parameter
$stmt->bindParam(':id', $id);
// Execute the statement
$stmt->execute();
// Fetch the item data as an associative array
$item = $stmt->fetch(PDO::FETCH_ASSOC);
// Return the item data
return $item;
}
function get_allcourses($pdo) {
$email = $_SESSION['email'];
$sql = "SELECT order_id, name, image_url FROM orders WHERE email = :email";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':email', $email);
$stmt->execute();
$courses = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
?>