当前位置: 首页 > 工具软件 > PHP ATC > 使用案例 >

php mysql pdo出错_php – PDO错误:SQLSTATE [HY000]:常规错误:2031

娄德运
2023-12-01

我得到这个令人讨厌的错误,虽然我有一个想法,为什么我得到它,我不能为我的生活找到一个解决方案.

if ($limit) {

$sth->bindValue(':page', $page - 1, PDO::PARAM_INT);

$sth->bindValue(':entries_per_page', $page * $entries_per_page, PDO::PARAM_INT);

}

$sth->execute($criteria);

查询包含占位符(:占位符).但是要添加这些LIMIT占位符,我需要使用手动方法(bindValue),否则引擎会将它们变成字符串.

我没有得到无效数量的参数错误,所以所有占位符已被正确绑定(我假设).

查询:

SELECT `articles`.*, `regional_municipalities`.`name` AS `regional_municipality_name`,

`_atc_codes`.`code` AS `atc_code`, `_atc_codes`.`name` AS `substance`

FROM `articles`

LEFT JOIN `_atc_codes`

ON (`_atc_codes`.`id` = `articles`.`atc_code`)

JOIN `regional_municipalities`

ON (`regional_municipalities`.`id` = `articles`.`regional_municipality`)

WHERE TRUE AND `articles`.`strength` = :strength

GROUP BY `articles`.`id`

ORDER BY `articles`.`id`

LIMIT :page, :entries_per_page

所有占位符值都驻留在$条件中,除了最后两个LIMIT,我用bindValue()手动绑定.

 类似资料: