Add try..catch blocks to payment queries to prevent 500 Empty Body on SQL errors
This commit is contained in:
@@ -52,19 +52,19 @@ LIMIT 1;
|
|||||||
* تُطابق 'Finished' فقط بينما خط الرحلات الحالي يكتب 'completed' — فتظهر
|
* تُطابق 'Finished' فقط بينما خط الرحلات الحالي يكتب 'completed' — فتظهر
|
||||||
* أرباح السائق ورحلاته أصفاراً.
|
* أرباح السائق ورحلاته أصفاراً.
|
||||||
*/
|
*/
|
||||||
$stmt = $con->prepare($sql);
|
try {
|
||||||
$stmt->bindValue(':driverID', $driverID);
|
$stmt = $con->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->bindValue(':driverID', $driverID);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
if ($stmt->rowCount() > 0) {
|
if ($stmt->rowCount() > 0) {
|
||||||
// Fetch the record
|
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
printSuccess($row);
|
||||||
|
} else {
|
||||||
printSuccess( $row);
|
printFailure("No wallet record found");
|
||||||
|
}
|
||||||
}
|
} catch (PDOException $e) {
|
||||||
else{
|
http_response_code(500);
|
||||||
// Print a failure message
|
echo json_encode(["status" => "error", "message" => "SQL Error: " . $e->getMessage()]);
|
||||||
printFailure($message = "No wallet record found");
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
@@ -12,20 +12,19 @@ WHERE
|
|||||||
AND created_at >= CURDATE();
|
AND created_at >= CURDATE();
|
||||||
";
|
";
|
||||||
// كان المعرّف يُدمج في نص الاستعلام مباشرةً — حقن SQL.
|
// كان المعرّف يُدمج في نص الاستعلام مباشرةً — حقن SQL.
|
||||||
$stmt = $con->prepare($sql);
|
try {
|
||||||
$stmt->bindValue(':driver_id', $driver_id);
|
$stmt = $con->prepare($sql);
|
||||||
$stmt->execute();
|
$stmt->bindValue(':driver_id', $driver_id);
|
||||||
|
$stmt->execute();
|
||||||
|
|
||||||
if ($stmt->rowCount() > 0) {
|
if ($stmt->rowCount() > 0) {
|
||||||
// Fetch the record
|
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||||
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
printSuccess($row);
|
||||||
|
} else {
|
||||||
|
printFailure("No wallet record found");
|
||||||
printSuccess( $row);
|
}
|
||||||
|
} catch (PDOException $e) {
|
||||||
}
|
http_response_code(500);
|
||||||
else{
|
echo json_encode(["status" => "error", "message" => "SQL Error: " . $e->getMessage()]);
|
||||||
// Print a failure message
|
|
||||||
printFailure($message = "No wallet record found");
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user