How can PHP be used to automate the process of exporting and importing data between two separate database servers?
To automate the process of exporting and importing data between two separate database servers using PHP, you can create scripts that connect to both databases, retrieve the data from one server, and insert it into the other server. This can be achieved by using PHP's database connection functions and SQL queries to transfer the data.
<?php
// Connect to the source database
$sourceConn = new mysqli('source_server', 'source_username', 'source_password', 'source_database');
// Connect to the destination database
$destConn = new mysqli('destination_server', 'destination_username', 'destination_password', 'destination_database');
// Retrieve data from the source database
$sourceData = $sourceConn->query('SELECT * FROM source_table');
// Insert data into the destination database
while ($row = $sourceData->fetch_assoc()) {
$destConn->query("INSERT INTO destination_table (column1, column2) VALUES ('" . $row['column1'] . "', '" . $row['column2'] . "')");
}
// Close the database connections
$sourceConn->close();
$destConn->close();
?>