我不熟悉 PDO 扩展,也找不到我的代码有什么问题。代码片段:
try {
$this->PDO->exec('SET AUTOCOMMIT = 0');
$this->PDO->exec('START TRANSACTION');
$this->PDO->prepare("UPDATE office_users
SET balance = balance - ?
WHERE id = ?")
->execute(array($sbs_price, $this->user->id)
);
$user_balance -= $sbs_price;
$this->PDO->prepare("UPDATE office_company
SET pay_days = pay_days + ?
WHERE inn = ?
AND user_id = ?")
->execute(array(
$sbs_period_days,
$company_inn,
$this->user->id)
);
$fin_string = $company_name.' ??? '.$company_inn.' ????????? '.$sbs_period_month. ' ???.';
$this->PDO->prepare("INSERT INTO office_fin_transactions
(user_id, date_register, dsc, amount, status)
VALUES (?, ?, ?, ?, ?)")
->execute(array(
$this->user->id.
date("Y-m-d H:i:s"),
$fin_string,
$sbs_price,
0)
);
$this->PDO->exec("COMMIT");
} catch (PDOException $Exception) {
$this->PDO->exec("ROLLBACK");
echo json_encode(array('result' => false,
'error' => $Exception->getMessage()));
exit;
}
echo json_encode(array('result'=>'success',
'inn' => $company_inn,
'sbs_period' => $sbs_period_month,
'company_name' => $company_name,
'balance' => $user_balance)
);
exit;
Run Code Online (Sandbox Code Playgroud)
在执行这段代码之前,在脚本开始时,PDO 是这样配置的:
$this->PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->PDO->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
Run Code Online (Sandbox Code Playgroud)
所有以前的查询都不会生成 PDO 异常,但最后一个 INSERT 查询会。
变量值:
$this->user->id == 158;
$fin_string == "??? "???????? ???????" - 2954 ??? 123456 ????????? 6 ???."
$sbs_price == 1000;
Run Code Online (Sandbox Code Playgroud)
表 office_fin_transactions 的结构是:

怎么了?请帮助,如果您有任何想法。