意外的 MySQL 事务提交
我有一个 PHP 脚本,可以使用 MySQL 数据库和 ODBC DB 连接(QODBC 到 QuickBooks)。设置是这样的:
Retrieve rows from MySQL database
Begin MySQL transaction:
Loop through rows
Process data
MySQL Insert/Update
MySQL Update
QODBC Selects/Inserts
End Loop
MySQL Delete
Commit Transaction
问题是,如果 QODBC 部分出现错误,则将提交到该点的 MySQL 命令。这会导致 MySQL 中出现重复和错误的数据。没有嵌套事务,并且所有查询成功/失败都得到解决(即没有致命错误或脚本过早退出)。
问题是 - 在同一个脚本中通过 PHP 连接到两个不同的数据库时是否存在问题?似乎发生的情况是,当脚本到达 ODBC 部分时,MySQL 事务将关闭并自动提交。
I have a PHP script that works with both a MySQL database and an ODBC DB connection (QODBC into QuickBooks). The setup is like this:
Retrieve rows from MySQL database
Begin MySQL transaction:
Loop through rows
Process data
MySQL Insert/Update
MySQL Update
QODBC Selects/Inserts
End Loop
MySQL Delete
Commit Transaction
The problem is, if there is an error in the QODBC section, the MySQL commands up to that point will be committed. This is leading to duplicate and wrong data in MySQL. There are no nested transactions and all the queries success/failure is being addressed (ie no fatal errors or premature exiting of a script).
The question is - is there a problem when connecting to two different databases via PHP, in the same script? What seems to be happening is when the script gets to the ODBC section, the MySQL transaction is closed and auto-committed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想说有两个潜在的原因:
I'd say there are two potential reasons: