PHP mysqli :: autocommit VS“START TRANSACTION” [英] PHP mysqli::autocommit VS "START TRANSACTION"

查看:121
本文介绍了PHP mysqli :: autocommit VS“START TRANSACTION”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的数据库层对象中,我们总是使用通过mysqli :: query执行的START TRANSACTION,ROLLBACK和COMMITSQL语句来管理事务。

In our database layer object, we have always managed transactions with "START TRANSACTION", "ROLLBACK" and "COMMIT" SQL statements executed via mysqli::query.

今天进行一些研究,我在MySQL手册中发现了这一提法< a>关于使用API​​级别调用来使用直接SQL管理事务VS:

Doing some research today, I discovered this mention in the MySQL Manual regarding using API level calls to manage a transaction VS using straight SQL:


重要

Important

许多API用于编写MySQL
客户端应用程序(如JDBC)
提供了自己的方法来启动
事务,可以使用(有时需要
)从
客户端发送
START TRANSACTION语句。有关详细信息,请参阅第20章连接器和
API或
API的文档。

Many APIs used for writing MySQL client applications (such as JDBC) provide their own methods for starting transactions that can (and sometimes should) be used instead of sending a START TRANSACTION statement from the client. See Chapter 20, Connectors and APIs, or the documentation for your API, for more information.

并且,在查找mysqli时,发现用于管理事务的mysqli :: autocommit,mysqli :: rollback和mysqli :: commit方法( http://us.php.net/manual/en/class.mysqli.php )。

And, upon looking closer at mysqli, found the mysqli::autocommit, mysqli::rollback and mysqli::commit methods for managing a transaction (http://us.php.net/manual/en/class.mysqli.php).

我的问题:是更好地使用这些mysqli等同和为什么?我可以找不到任何地方说,如果或为什么这些函数的性能比他们的直SQL对应的更好。

My question: is it better to use these mysqli equivalents and why? I can find no mention anywhere that says if or why these functions perform better than their straight SQL counterparts.

推荐答案

是数据访问包装器需要知道事务何时开始/结束的原因。例如,在我的头顶部,连接池方案必须知道在事务中间什么时候完成了先前使用的连接,并且不返回到连接池以便在这种情况下重新使用。

It's possible there might be reasons why a data access wrapper would need to know when a transaction was started/ended. For example off the top of my head, a connection-pooling scheme would have to know when a previously-used connection was finished with in the middle of a transaction, and not return it to the connection pool for re-use in that case.

我不知道 mysqli 中的任何问题,这将要求您使用本机方法, SQL版本,但它可能在一般情况下...这就是为什么它只有有时应该。在任何情况下,PHP方法比SQL字符串版本更容易阅读,所以我会说,无论如何。

I'm not aware of any issues in mysqli that would require you to use the native method rather than the SQL version, but it's possibly in the general case... that's why it's only "sometimes should". In any case, the PHP method is easier to read than the SQL-string version, so I'd say go with that anyway.

这篇关于PHP mysqli :: autocommit VS“START TRANSACTION”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆