connect_error) { http_response_code(500); echo json_encode(["status" => "error", "message" => "DB connection failed"]); exit; } $mysqli->set_charset("utf8mb4"); return $mysqli; } function getJsonInput() { $raw = file_get_contents("php://input"); $data = json_decode($raw, true); if (!is_array($data)) { return []; } return $data; } function send($code, $arr) { http_response_code($code); echo json_encode($arr); exit; }