prepare($sql); // The execute method returns true on success and false on failure. $success = $stmt->execute([ ':latitude' => $latitude, ':longitude' => $longitude, ':heading' => $heading, ':speed' => $speed, ':distance' => $distance, ':status' => $status, ':updated_at' => $updated_at, ':driver_id' => $driver_id ]); // The reliable way to check for success is if execute() returns true // and doesn't throw an exception. We no longer need rowCount(). if ($success) { // Print a success message jsonSuccess(null, "Car location updated successfully"); } else { // This case is rare but might happen if execute fails without an exception jsonError("Failed to update car location"); } } catch (PDOException $e) { // A real database error occurred. http_response_code(500); // You can log the detailed error for debugging // error_log('Database error: ' . $e->getMessage()); jsonError('Database error occurred'); } ?>