File db.php di folder includes digunakan untuk mengatur koneksi ke database dengan kode PHP berikut:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "nama_database";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}
?>
3. Membuat Fungsi CRUD
File functions.php di folder includes mengatur fungsi CRUD (Create, Read, Update, Delete). Berikut adalah kode untuk masing-masing fungsi:
- Create:
 function createData($table, $data) {
  global $conn;
  $columns = implode(", ", array_keys($data));
  $values = implode("', '", array_values($data));
  $sql = "INSERT INTO $table ($columns) VALUES ('$values')";
  return $conn->query($sql);
}
- Read:
function readData($table, $conditions = []) {
  global $conn;
  $sql = "SELECT * FROM $table";
  if (!empty($conditions)) {
    $sql .= " WHERE " . implode(" AND ", $conditions);
  }
  return $conn->query($sql);
}
- Update:
function updateData($table, $data, $conditions) {
  global $conn;
  $set = [];
  foreach ($data as $column => $value) {
    $set[] = "$column='$value'";
  }
  $sql = "UPDATE $table SET " . implode(", ", $set) . " WHERE " . implode(" AND ", $conditions);
  return $conn->query($sql);
}
- Delete: