0
我使用PDO在PHP/MySql上運行。LAST_INSERT_ID()在雙表插入時鏈接
比方說,我有這樣的查詢。 $ OrderId在「訂單」表中自動遞增。 我可以使用LAST_INSERT_ID()在「Orders」和「BoughtItems」表中插入$ OrderId。
INSERT INTO Orders (OrderId, CustomerName, CustomerEmail, OrderTotal, OrderTaxes)
SET @order_id = LAST_INSERT_ID();
INSERT INTO boughtItems (OrderId,ProductId,OrderedQty) Values (@order_id, :productid_1,
:name_1),(@order_id, :productid_2, :name_2),(@order_id, :productid_3, :name_3)
如果兩個人在同一時間執行不同的命令會發生什麼?
他們都得到相同的$ OrderId並混淆他們的訂單的任何危險?
謝謝你的時間!