我的CakePHP 3.0应用程序使用一个MySQL数据库,目前有两个结构相同(但数据不同)的表。我想合并这两个表,但要跟踪数据,因为它有关联。
所以,我想我只是从一个表中读取记录,然后用一个标志将它们复制到另一个表中,以指示它们来自旧表,如下所示:
public function copyarchive() {
$oldalbums= TableRegistry::get('Archivealbums');
$newalbums= TableRegistry::get('Albums');
$albumlist = $oldalbums->find(); // Get all archived albums
foreach($albumlist as $oldalbum) {
// Copy album details to album table and get new id
$newalbum = $newalbums->newEntity([
'is_archive' => 1,
'name' => $oldalbum->name,
'date' => $oldalbum->date,
'description' => $oldalbum->description,
'order' => $oldalbum->order,
]);
if ($newalbums->save($newalbum)) {
$id = $newalbum->id;
// ... now do other things ...
}
}
}
我收到以下错误:
Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order) VALUES (1, 'Pre-1920\'s', '2013-10-22 23:00:00', '<p>\r\n Photos from bef' at line 1
SQL查询如下所示:
INSERT INTO albums (is_archive, name, date, description, order) VALUES (:c0, :c1, :c2, :c3, :c4)
它还建议“这可能是使用自动表格造成的吗?”
我在做傻事吗?