以下是我的疑问
$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查询中实现事务,我想在其中一个查询失败时失败所有查询.上面的代码抛出一个错误(“致命错误:调用未定义的方法MysqLi :: beginTransaction()”).请有任何更好的解决方案或想法来解决问题.谢谢你的帮助
解决方法:
$db->begin_transaction();
不
$db->beginTransaction();
http://www.php.net/manual/en/mysqli.begin-transaction.php
如果早于PHP 5.5,那么使用
$db->autocommit(true);
代替
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。