【发布时间】:2014-02-23 12:45:31
【问题描述】:
我的 PHP/Mysql 脚本分阶段工作:
Insert Customer info
Get new customer's ID via mysqli_insert_id(blah)
Insert into ADDRESS using new customer's ID
Insert into PHONE using new customer's ID
Insert into CONTACTS using new customer's ID
我的问题是:如果后面的插入语句之一出现问题,MYSQL 会停止并当然会抛出错误,但最初的 Customer INSERT 已经触发并成功。现在,如果我们返回并更正输入中的错误并尝试再次执行此操作,我们将获得该客户的多个部分条目。
所以问题:有没有办法测试所有 MySQL 插入是否有错误,如果没有发现,那么继续提交所有错误?
例如:
Insert Customer info (check for would-be errors; don't actually insert)
Get new customer's ID...
Insert into ADDRESS...(check for would-be errors; don't actually insert)
Insert into PHONE...(check for would-be errors; don't actually insert)
Insert into CONTACTS...(check for would-be errors; don't actually insert)
好的,既然没有抛出错误并且实际上没有插入任何内容,请执行所有预先筛选的插入!
这存在吗?
【问题讨论】:
-
你熟悉mysql事务吗?听起来像你需要的:dev.mysql.com/doc/refman/5.0/en/commit.html