gpt4 book ai didi

php - 处理订单 : Save recipient address, 或通过 lastInsertId() 引用?

转载 作者:行者123 更新时间:2023-11-29 14:29:37 25 4
gpt4 key购买 nike

我正在使用 PHP/MySQL 开发电​​子车/商店。

我从一开始就决定为地址建立一个单独的表,这样我就不会存储重复的数据(例如,每次向同一地址下订单时,该订单将存储address_id而不是门,街道、城镇、城市、邮政编码等

现在我正在进行查询来处理订单,我将为用户提供一个选项
a) 从存储的列表(customer_id、address_id)中选择一个地址 - 或 -
b) 创建一个新地址(查询返回lastInsertId())。

我有疑问,因为我不确定是否在任何情况下 lastInsertId() 会返回错误的 address_id,因此系统会发送订单存储地址错误?或者在处理订单时传递了错误的 ID 号?

我可以采取哪些额外步骤来使这样的系统万无一失,以便永远不会给出错误的地址?

最佳答案

For LAST_INSERT_ID(), the most recently generated ID is maintained in the server on a per-connection basis. It is not changed by another client. It is not even changed if you update another AUTO_INCREMENT column with a nonmagic value (that is, a value that is not NULL and not 0). Using LAST_INSERT_ID() and AUTO_INCREMENT columns simultaneously from multiple clients is perfectly valid. Each client will receive the last inserted ID for the last statement that client executed.

查看更多:http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html

关于php - 处理订单 : Save recipient address, 或通过 lastInsertId() 引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10270763/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com