|
|
|
ขอวิธีการ Copy table จากอีกฐาน ไป อีกฐานครับ php mysql หาใน Google แล้ว เจอแต่การ Copy table ในฐานเดียวกันส่วนใหญ่ |
|
|
|
|
|
|
|
มีหลายวิธี
Code (SQL)
INSERT INTO destination_db.new_table
SELECT * FROM source_db.old_table;
CLI
mysqldump -u username -p password source_db table_to_copy > table_to_copy.sql
mysql -u username -p password destination_db < table_to_copy.sql
Code (PHP)
<?php
$sourceDb = new mysqli("source_host", "source_user", "source_password", "source_db");
$destinationDb = new mysqli("destination_host", "destination_user", "destination_password", "destination_db");
$tableName = "table_to_copy";
$sql = "SELECT * FROM $tableName";
$result = $sourceDb->query($sql);
while ($row = $result->fetch_assoc()) {
$columns = implode(",", array_keys($row));
$values = implode("','", array_values($row));
$insertSql = "INSERT INTO $tableName ($columns) VALUES ('$values')";
$destinationDb->query($insertSql);
}
echo "Table $tableName copied successfully.";
?>
|
|
|
|
|
Date :
2023-02-14 11:29:51 |
By :
009 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากครับ
|
|
|
|
|
Date :
2023-02-21 12:15:52 |
By :
skynetcom |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|