61 lines
1.7 KiB
PHP
61 lines
1.7 KiB
PHP
<?php
|
|
require_once __DIR__ . "/../config/db.php";
|
|
|
|
function getCertifications($mysqli, $limit = null) {
|
|
$certs = [];
|
|
$sql = "SELECT * FROM certifications ORDER BY id DESC";
|
|
if ($limit !== null) {
|
|
$sql .= " LIMIT " . intval($limit);
|
|
}
|
|
$result = $mysqli->query($sql);
|
|
if ($result && $result->num_rows > 0) {
|
|
while ($row = $result->fetch_assoc()) {
|
|
$certs[] = $row;
|
|
}
|
|
}
|
|
return $certs;
|
|
}
|
|
|
|
function getCertificationById($mysqli, $id) {
|
|
$sql = "SELECT * FROM certifications 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 addCertification($mysqli, $title, $issuer, $date_issued, $icon) {
|
|
$sql = "INSERT INTO certifications (title, issuer, date_issued, icon) VALUES (?, ?, ?, ?)";
|
|
$stmt = $mysqli->prepare($sql);
|
|
if ($stmt) {
|
|
$stmt->bind_param("ssss", $title, $issuer, $date_issued, $icon);
|
|
return $stmt->execute();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function editCertification($mysqli, $id, $title, $issuer, $date_issued, $icon) {
|
|
$sql = "UPDATE certifications SET title = ?, issuer = ?, date_issued = ?, icon = ? WHERE id = ?";
|
|
$stmt = $mysqli->prepare($sql);
|
|
if ($stmt) {
|
|
$stmt->bind_param("ssssi", $title, $issuer, $date_issued, $icon, $id);
|
|
return $stmt->execute();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
function deleteCertification($mysqli, $id) {
|
|
$sql = "DELETE FROM certifications WHERE id = ?";
|
|
$stmt = $mysqli->prepare($sql);
|
|
if ($stmt) {
|
|
$stmt->bind_param("i", $id);
|
|
return $stmt->execute();
|
|
}
|
|
return false;
|
|
}
|
|
?>
|