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 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();
where $db is the PDO connection object you're using to use MySQL,
see the manual
However nothing from the transaction is run until you call PDO::commit
$db->commit();
after which you can call PDO::rollBack
$db->rollBack();
if anything has gone wrong.