File "read.php"

Full path: /home2/santhos2/public_html/bharath-coe.firstmatrix.in.net/api/staff_roles/read.php
File size: 1.1 KiB (1123 bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Back

<?php
require_once '../../config/config.php';
header('Content-Type: application/json');

try {
    $filterSearch = isset($_GET['filter_search']) ? trim($_GET['filter_search']) : '';
    $filterStatus = isset($_GET['filter_status']) ? trim($_GET['filter_status']) : '';

    $conditions = [];
    $bindings = [];
    if ($filterSearch !== '') { $conditions[] = 'role_name LIKE :fs'; $bindings[':fs'] = "%$filterSearch%"; }
    if ($filterStatus !== '') { $conditions[] = 'status = :fst'; $bindings[':fst'] = $filterStatus; }
    $where = count($conditions) ? ('WHERE ' . implode(' AND ', $conditions)) : '';

    $sql = "SELECT role_id, role_name, status, created_at, updated_at FROM staff_role_types $where ORDER BY role_name ASC";
    $stmt = $pdo->prepare($sql);
    foreach($bindings as $k=>$v){ $stmt->bindValue($k,$v,PDO::PARAM_STR);} 
    $stmt->execute();
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
    echo json_encode(['success'=>true,'data'=>$rows]);
} catch (Throwable $e) {
    http_response_code(500);
    echo json_encode(['success'=>false,'message'=>$e->getMessage()]);
}
?>


PHP File Manager