我有 2 个 MySQL 表
表#1 - 容器:
container_id INT (PK AI)
start_time DATETIME
表#2 - 预订
reservation_id INT (PK AI)
reservation_time DATETIME
container_id INT (FK)
PHP代码:
mysqli_query($dbc,'SET AUTOCOMMIT=0');
mysqli_query($dbc,'START TRANSACTION');
$q1 = "INSERT INTO container (start_time) VALUES
('2012-07-03 11:00:00')";
$q2 = "INSERT INTO reservation (reservation_time, container_id) VALUES
('2012-07-03 11:00:00', LAST_INSERT_ID())";
$r1 = mysqli_query($dbc, $q1);
$r2 = mysqli_query($dbc, $q2);
if ($r1 && r2){
mysqli_query($dbc, 'COMMIT');
} else {
mysqli_query($dbc, 'ROLLBACK');
}
我做错了什么?$r2 返回假。LAST_INSERT_ID() 不起作用