How can PHP be utilized to generate CSV files for data synchronization between two different servers?
To generate CSV files for data synchronization between two different servers using PHP, you can fetch the data from one server, format it as CSV, and then save the CSV file. This file can then be transferred to the second server for synchronization.
<?php
// Fetch data from server 1
$data = array(
array('Name', 'Age', 'Email'),
array('John Doe', 30, 'john.doe@example.com'),
array('Jane Smith', 25, 'jane.smith@example.com')
);
// Open a new CSV file
$csvFile = fopen('data.csv', 'w');
// Write data to CSV file
foreach ($data as $row) {
fputcsv($csvFile, $row);
}
// Close the CSV file
fclose($csvFile);
// Transfer the CSV file to server 2 for synchronization
// This step will depend on your specific server setup
?>