setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Set default fetch mode to associative array $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); } catch (PDOException $e) { die(json_encode([ 'status' => 'error', 'message' => 'Connection failed: ' . $e->getMessage() ])); } // Ensure the response is JSON header('Content-Type: application/json; charset=utf-8');