Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created Nov 22, 2020
Embed
What would you like to do?
<?php
function deleteEmployee($id)
{
$db = getDatabase();
$statement = $db->prepare("DELETE FROM employees WHERE id = ?");
return $statement->execute([$id]);
}
function updateEmployee($name, $id)
{
$db = getDatabase();
$statement = $db->prepare("UPDATE employees SET name = ? WHERE id = ?");
return $statement->execute([$name, $id]);
}
function getEmployeeById($id)
{
$db = getDatabase();
$statement = $db->prepare("SELECT id, name FROM employees WHERE id = ?");
$statement->execute([$id]);
return $statement->fetchObject();
}
function saveEmployee($name)
{
$db = getDatabase();
$statement = $db->prepare("INSERT INTO employees(name) VALUES (?)");
return $statement->execute([$name]);
}
function getEmployees()
{
$db = getDatabase();
$statement = $db->query("SELECT id, name FROM employees");
return $statement->fetchAll();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment