Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created November 22, 2020 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/e0964045a4ab29aa81222c90a833bb10 to your computer and use it in GitHub Desktop.
Save parzibyte/e0964045a4ab29aa81222c90a833bb10 to your computer and use it in GitHub Desktop.
<?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