This commit is contained in:
Hamza-Ayed
2026-04-28 15:14:59 +03:00
parent 3fa9aee14e
commit 06cbf1e19d
2 changed files with 24 additions and 10 deletions

View File

@@ -139,17 +139,31 @@ $sql = "INSERT INTO `ride` (
)";
try {
// 3. الإدخال في قاعدة البيانات الرئيسية (Main DB)
$stmtMain = $con->prepare($sql);
$stmtMain->execute($data);
$insertedId = $con->lastInsertId(); // ID الرحلة الجديد
// 3. الإدخال في قاعدة بيانات الرحلات أولاً (Ride DB - المرجع الأساسي)
$stmtRide = $con_ride->prepare($sql);
$stmtRide->execute($data);
$insertedId = $con_ride->lastInsertId(); // ID الرحلة الجديد
// 4. الإدخال في قاعدة بيانات الرحلات (Ride DB) للأرشفة والتزامن
if (!$insertedId) {
jsonError("Failed to create ride");
}
// 4. الإدخال في قاعدة البيانات الرئيسية ثانياً (Main DB) بنفس الـ ID
try {
$stmtRide = $con_ride->prepare($sql);
$stmtRide->execute($data);
} catch (Exception $e) {
error_log("⚠️ RideDB Insert Warning: " . $e->getMessage());
$sqlMain = "INSERT INTO `ride` (
`id`, `start_location`, `end_location`, `date`, `time`, `endtime`,
`price`, `passenger_id`, `driver_id`, `status`, `carType`,
`price_for_driver`, `price_for_passenger`, `distance`
) VALUES (
:id, :start_location, :end_location, :date, :time, :endtime,
:price, :passenger_id, :driver_id, :status, :carType,
:price_for_driver, :price_for_passenger, :distance
)";
$stmtMain = $con->prepare($sqlMain);
$data[':id'] = $insertedId;
$stmtMain->execute($data);
} catch (Exception $eMain) {
error_log("⚠️ Main DB Sync Warning: " . $eMain->getMessage());
}
if ($insertedId) {