PDO 异常 "SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens"
PDO Exception "SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens"
我不熟悉 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;
在执行此代码之前,在脚本的开头,PDO 是这样配置的:
$this->PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->PDO->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
之前的所有查询都不会生成 PDO 异常,但最后一个 INSERT 查询会生成。
变量值:
$this->user->id == 158;
$fin_string == "ООО "Тестовые системы" - 2954 ИНН 123456 продление 6 мес."
$sbs_price == 1000;
table office_fin_transactions 的结构是:
怎么了?如果您有任何想法,请提供帮助。
$this->user->id
后面有一个点而不是逗号,所以它实际上只是一个 4 元素数组。
我不熟悉 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;
在执行此代码之前,在脚本的开头,PDO 是这样配置的:
$this->PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->PDO->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
之前的所有查询都不会生成 PDO 异常,但最后一个 INSERT 查询会生成。
变量值:
$this->user->id == 158;
$fin_string == "ООО "Тестовые системы" - 2954 ИНН 123456 продление 6 мес."
$sbs_price == 1000;
table office_fin_transactions 的结构是:
怎么了?如果您有任何想法,请提供帮助。
$this->user->id
后面有一个点而不是逗号,所以它实际上只是一个 4 元素数组。