I'm using slim php and i have this simple paginated end point to get all clients, i feel like i could do some things here better, so i would appreciate all suggestions, if possible please give me code example with suggested improvements. Thank you in advance.$app->get('/api/clients', function ($request, $response, $args) {    require_once 'dbConnect.php';    require_once 'shared/securityService.php';    $queryParams = $request->getQueryParams();    $total = getTotalCount($mysqli, $queryParams[group]);    $pageSize = $queryParams[pageSize];    $totalPages = ceil($total / $pageSize);    $offset = ($queryParams[page] - 1)  * $pageSize;    if(is_numeric($queryParams[group])) {        $stmt = $mysqli->prepare(SELECT id, firstName, lastName, birthDate, phoneNumber, address,            contactPerson, contactPersonPhoneNumber FROM client WHERE groupId = ? ORDER BY            id LIMIT $pageSize OFFSET $offset);        $stmt->bind_param(i, $queryParams[group]);    } else {        $stmt = $mysqli->prepare(SELECT id, firstName, lastName, birthDate, phoneNumber, address,            contactPerson, contactPersonPhoneNumber FROM client             ORDER BY id LIMIT $pageSize OFFSET $offset);                }    $stmt->execute();    $stmt->bind_result($id, $firstName, $lastName, $birthDate, $phoneNumber,         $address, $contactPerson, $contactPersonPhoneNumber);    $data = null;    while ($stmt->fetch()) {        $data['items'][] = array(            'id' => $id,            'firstName' => $firstName,            'lastName' => $lastName,            'birthDate' => $birthDate,            'phoneNumber' => $phoneNumber,            'address' => $address,            'contactPerson' => $contactPerson,            'contactPersonPhoneNumber' => $contactPersonPhoneNumber        );    }    $data['totalItems'] = $total;    $stmt->close();    $mysqli->close();    echo json_encode($data);});function getTotalCount($mysqli, $groupId) {    if(is_numeric($groupId)) {        $totalStmt = $mysqli->prepare(SELECT COUNT(id) FROM client WHERE groupId = ?);        $totalStmt->bind_param(i, $groupId);    } else {        $totalStmt = $mysqli->prepare(SELECT COUNT(id) FROM client);    }    $totalStmt->execute();    $totalStmt->bind_result($total);    $totalStmt->fetch();    $totalStmt->close();    return $total;}
Paginated method to get all items
php;mysql;mysqli;slim