Php事务定义,php – 开始事务未定义

mysql中未定义begin事务.我实际上使用它在我的代码中运行多个查询来将一行从一个表移动到另一个表.很多帮助将不胜感激.好的,我的问题是,为什么我的Begin_transaction()没有定义?

If(isset($trade_id)){

$trade_id= $_GET['trade_id'];

}

require_once('connect.php');

$mysqli = new mysqli($database_hostname, $database_username, $database_password, $database_name) or exit("Error connecting to database");

try {

// First of all, let's begin a transaction

$mysqli->begin_transaction();

// A set of queries; if one fails, an exception should be thrown

$mysqli->query("INSERT INTO `trade_history1` (session_id, trade_id, selection, date, type, size, bidprice, offerprice, stoploss, takeprofit, profitandloss, dateclose, close)

SELECT session_id, trade_id, selection, date, type, size, bidprice, offerprice, stoploss, takeprofit, profitandloss, dateclose, close

FROM `opentrades`

WHERE `trade_id` = " . $tradeid);

$mysqli->query("DELETE FROM `opentrades` WHERE `trade_id` = " . $trade_id);

// If we arrive here, it means that no exception was thrown

// i.e. no query has failed, and we can commit the transaction

$mysqli->commit();

$_SESSION['message'] = 'Successfully deleted';

} catch (Exception $e) {

// An exception has been thrown

// We must rollback the transaction

$_SESSION['message'] = 'Unable to delete';

$mysqli->rollback();

}

$mysqli->close();

// if we successfully delete this, we

if ($successfullyDeleted) {

$_SESSION['message'] = 'Successfully deleted';

} else {

$_SESSION['message'] = 'Unable to delete';

}

header('Location: js.php');

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值