I have 2 MySQL tables
table#1 - container:
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 返回 false。LAST_INSERT_ID() 不起作用。
or die(mysql_error());
或类似的语句)。 - Nannecontainer_id INT(PK AI)
,PK代表主键,AI代表自动增量。 - Mihai Stancu