From 80a99fef7d56b7494fca30749d04c17991d4ace1 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Sat, 1 Aug 2026 05:58:44 +0300 Subject: [PATCH] Add try..catch blocks to payment queries to prevent 500 Empty Body on SQL errors --- .../v2/main/ride/payment/getAllPayment.php | 26 +++++++++--------- .../v2/main/ride/payment/getCountRide.php | 27 +++++++++---------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/payment_server/v2/main/ride/payment/getAllPayment.php b/payment_server/v2/main/ride/payment/getAllPayment.php index 24699d3..9c5a0a1 100644 --- a/payment_server/v2/main/ride/payment/getAllPayment.php +++ b/payment_server/v2/main/ride/payment/getAllPayment.php @@ -52,19 +52,19 @@ LIMIT 1; * تُطابق 'Finished' فقط بينما خط الرحلات الحالي يكتب 'completed' — فتظهر * أرباح السائق ورحلاته أصفاراً. */ -$stmt = $con->prepare($sql); -$stmt->bindValue(':driverID', $driverID); -$stmt->execute(); +try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':driverID', $driverID); + $stmt->execute(); -if ($stmt->rowCount() > 0) { - // Fetch the record - $row = $stmt->fetchAll(PDO::FETCH_ASSOC); - - printSuccess( $row); - -} - else{ - // Print a failure message - printFailure($message = "No wallet record found"); + if ($stmt->rowCount() > 0) { + $row = $stmt->fetchAll(PDO::FETCH_ASSOC); + printSuccess($row); + } else { + printFailure("No wallet record found"); + } +} catch (PDOException $e) { + http_response_code(500); + echo json_encode(["status" => "error", "message" => "SQL Error: " . $e->getMessage()]); } ?> \ No newline at end of file diff --git a/payment_server/v2/main/ride/payment/getCountRide.php b/payment_server/v2/main/ride/payment/getCountRide.php index 92d2494..5375edd 100644 --- a/payment_server/v2/main/ride/payment/getCountRide.php +++ b/payment_server/v2/main/ride/payment/getCountRide.php @@ -12,20 +12,19 @@ WHERE AND created_at >= CURDATE(); "; // كان المعرّف يُدمج في نص الاستعلام مباشرةً — حقن SQL. -$stmt = $con->prepare($sql); -$stmt->bindValue(':driver_id', $driver_id); -$stmt->execute(); +try { + $stmt = $con->prepare($sql); + $stmt->bindValue(':driver_id', $driver_id); + $stmt->execute(); -if ($stmt->rowCount() > 0) { - // Fetch the record - $row = $stmt->fetchAll(PDO::FETCH_ASSOC); - - - printSuccess( $row); - -} - else{ - // Print a failure message - printFailure($message = "No wallet record found"); + if ($stmt->rowCount() > 0) { + $row = $stmt->fetchAll(PDO::FETCH_ASSOC); + printSuccess($row); + } else { + printFailure("No wallet record found"); + } +} catch (PDOException $e) { + http_response_code(500); + echo json_encode(["status" => "error", "message" => "SQL Error: " . $e->getMessage()]); } ?> \ No newline at end of file