INSERT INTO `table1`
SET `field1` = 'value1',
`field2` = 'value2',
`field3` = 'value3';
INSERT INTO `table2`
SET id = (SELECT LAST_INSERT_ID()),
`field` = 'value';
我正在尝试使用DB::query(Database::INSERT,$query);
- 它不起作用
$ query - 我写在消息顶部
答案 0 :(得分:0)
使用ORM
模块,如:
// We make first insert
$table1_orm = ORM::factory('Item') // `table1`
->values(array(
'field1' => 'value1',
'field2' => 'value2',
'field3' => 'value3',
))
->save(); // Now saved Model is in $table1_orm variable. ID is in $table1_orm->id
// Now second insert
ORM::factory('Item2') // `table2`
->values(array(
'id' => $table1_orm->id,
'field' => 'value'
))
->save();