如何使用SLIM框架创建MySQL事务 [英] How to create MySQL transaction using SLIM framework
问题描述
我正在使用Slim
框架来创建RESTful API
.如何创建事务来执行多个SQL
语句和/或能够回滚其中一些语句?
I am using the Slim
framework to create a RESTful API
. How can I create a transaction to execute multiple SQL
statements and/or to be able to rollback some of those statements?
推荐答案
SLIM
不附带MySQL,因此基本上,您可以使用PDO或MySQLi以正常方式进行操作,因此基本上(假定PDO ),您正在寻找:
SLIM
doesn't come with MySQL attached, so basically you'd do it the normal way, with either PDO or MySQLi, so basically (assuming PDO) you're looking for:
$db->beginTransaction();
其中$db
是用于使用MySQL的PDO连接对象,
请参见手册
where $db
is the PDO connection object you're using to use MySQL,
see the manual
但是,直到您调用 PDO::commit
However nothing from the transaction is run until you call PDO::commit
$db->commit();
之后,您可以调用 PDO::rollBack
after which you can call PDO::rollBack
$db->rollBack();
如果出了什么问题.
这篇关于如何使用SLIM框架创建MySQL事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!