query('SELECT * FROM role_permissions'); $all_permissions = $stmt->fetchAll(PDO::FETCH_ASSOC); $permissions = []; foreach ($all_permissions as $p) { $permissions[$p['role']][$p['resource']][$p['action']] = $p['fields'] ?? '*'; } } catch (PDOException $e) { // Handle database errors, maybe return false or log the error return false; } } if (isset($permissions[$role][$resource][$action])) { if (in_array($action, ['read', 'update'])) { return $permissions[$role][$resource][$action]; } return true; } return false; }