query($sql); if ($result && $result->num_rows > 0) { // Loop through the database rows and push names into the array while ($row = $result->fetch_assoc()) { $projects[] = $row; } } return $projects; } function getThreeProjects($mysqli){ $projects = []; $sql = "SELECT * FROM projects ORDER BY id DESC LIMIT 3"; $result = $mysqli->query($sql); if ($result && $result->num_rows > 0) { // Loop through the database rows and push names into the array while ($row = $result->fetch_assoc()) { $projects[] = $row; } } return $projects; } function getProjectById($mysqli, $id) { $sql = "SELECT * FROM projects WHERE id = ?"; $stmt = $mysqli->prepare($sql); if ($stmt) { $stmt->bind_param("i", $id); $stmt->execute(); $result = $stmt->get_result(); return $result->fetch_assoc(); } return null; } function addProject($mysqli, $title, $des, $techstack, $url, $img_url) { $sql = "INSERT INTO projects (title, des, techstack, url, img_url) VALUES (?, ?, ?, ?, ?)"; $stmt = $mysqli->prepare($sql); if ($stmt) { $stmt->bind_param("sssss", $title, $des, $techstack, $url, $img_url); return $stmt->execute(); } return false; } function editProject($mysqli, $id, $title, $des, $techstack, $url, $img_url) { $sql = "UPDATE projects SET title = ?, des = ?, techstack = ?, url = ?, img_url = ? WHERE id = ?"; $stmt = $mysqli->prepare($sql); if ($stmt) { $stmt->bind_param("sssssi", $title, $des, $techstack, $url, $img_url, $id); return $stmt->execute(); } return false; } function deleteProject($mysqli, $id) { $sql = "DELETE FROM projects WHERE id = ?"; $stmt = $mysqli->prepare($sql); if ($stmt) { $stmt->bind_param("i", $id); return $stmt->execute(); } return false; } ?>