0
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 - 我写在消息的顶部

4

1 回答 1

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();
于 2013-05-28T13:16:27.207 回答