我有一个数据和查询如下:
$msg = 'ABCDEFGH|AMI16025|GCIT4717730132|454627-028411|2.00|CIT|472642|03|INR|DIRECT|NA|NA|NA|31-08-2016 12:07:54|0300|NA|nitish.dola@gmail.com|09706125041|NA|NA|NA|NA|NA|NA|Success|8B4CB175614193B447959AD852B114FD709E6664FAC0566C0566B440BB8EA446';
$splitdata = explode('|', $msg);
$customer_id = $splitdata[1];
$transaction_id = $splitdata[2];
$bank_id = $splitdata[5];
$bank_merchant_id = $splitdata[6];
$trans_type = $splitdata[7];
$pay_date = date('Y-m-d H:i:s', strtotime($splitdata[13]));
$response_message = '';
$response_message .= $splitdata[24];
$amount_paid = $splitdata[4];
$bank_response_code = $splitdata[14];
$curreny = $splitdata[8];
if($bank_response_code == "0300") // success trans condition
{
$success = true;
//update the database
$sql = "UPDATE ami_delegate_payments SET
payment_status = :payment_status,
amount_paid = :amount_paid,
pay_date = :pay_date,
payment_type = :payment_type,
transaction_id = :transaction_id,
bank_id = :bank_id,
bank_merchant_id = :bank_merchant_id,
bank_response_code = :bank_response_code,
bank_message = :msg,
curreny = :curreny
WHERE customer_id = :customer_id";
$pdo->beginTransaction();
try {
$stmt = $pdo->prepare($sql);
$payment_status = 1;
$stmt->bindParam(':payment_status', $payment_status, PDO::PARAM_STR);
$stmt->bindParam(':amount_paid', $amount_paid, PDO::PARAM_STR);
$stmt->bindParam(':pay_date', $pay_date, PDO::PARAM_STR);
$stmt->bindParam(':payment_type', $payment_type, PDO::PARAM_STR);
$stmt->bindParam(':transaction_id', $transaction_id, PDO::PARAM_STR);
$stmt->bindParam(':bank_id', $bank_id, PDO::PARAM_STR);
$stmt->bindParam(':bank_merchant_id', $bank_merchant_id, PDO::PARAM_STR);
$stmt->bindParam(':bank_response_code', $bank_response_code, PDO::PARAM_STR);
$stmt->bindParam(':msg', $msg, PDO::PARAM_STR);
$stmt->bindParam(':curreny', $curreny, PDO::PARAM_STR);
$stmt->bindParam(':customer_id', $customer_id, PDO::PARAM_STR);
$stmt->execute();
var_dump($stmt->debugDumpParams);
if($stmt->rowCount()) {
echo 'Added';
}else{
echo 'No';
}
exit;
}catch (PDOException $e) {
var_dump($e); exit;
}
Tghough我总是得到输出
NULLED Added
实际上数据没有更新!怎么了 。客户ID AMI16025
存在于数据库
答案 0 :(得分:0)
you call beginTransaction()
but don't commit()
so PDO automatically does a rollback()
From manual
if you didn't explicitly commit the transaction, then it is assumed that something went awry, so the rollback is performed for the safety of your data.