以下是我的查询
$db= new mysqli('localhost','user','passcode','dbname');
try {
// First of all, let's begin a transaction
$db->beginTransaction();
// A set of queries; if one fails, an exception should be thrown
$query1="insert into table1(id,name) values('1','Dan')";
$query2="insert into table2(id,name) values('2','Anaba')";
// If we arrive here, it means that no exception was thrown
// i.e. no query has failed, and we can commit the transaction
$db->commit();
} catch (Exception $e) {
// An exception has been thrown
// We must rollback the transaction
$db->rollback();
}
请我尝试通过 php 在 mysql 查询中实现事务,当其中一个查询失败时,我想使所有查询失败。上面的代码抛出错误(“Fatal error: Call to undefined method mysqli::beginTransaction()”)。请问有没有更好的解决方案或想法来解决这个问题。感谢您的帮助