所以我有两个DB,一个用于草稿,用于现场直播。
// Connect to the draft database
$connDraft = mysqli_connect('###.###.##.##','user','pass') OR die("There was a problem connecting to the draft database.");
// Select database
mysqli_select_db($connDraft, "draftDB") OR die("There was a problem selecting the draft database.");
// Connect to the live database
$connLive = mysqli_connect('###.###.##.##','user','pass') OR die("There was a problem connecting to the live database.");
// Select database
mysqli_select_db($connLive, "liveDB") OR die("There was a problem selecting the live database.");
表结构和表名以及所有内容都是一样的。我只需要:
如果entry_id存在于实时,则更新否则插入新记录。
A - 从表格复制到表格我会使用
INSERT INTO table2
SELECT * FROM table1;
B - 插入与更新我使用
INSERT ... ON DUPLICATE KEY UPDATE
C - 从1个DB移动到另一个,我使用 ???
INSERT INTO liveDB.TableA
SELECT * FROM draftDB.TableB
我的困惑是如何使用 A & B 串联。我在线查找样本有困难。此外, C 是实现此目的的正确方法。
示例表结构将是......
entry_id,title,status,date_created,data_edited