PDOStatement::execute 值不适用于 WHERE 条件和 HAVING 条件
PDOStatement::execute Values doesn't work with WHERE Condition & HAVING Condition
我有一个 erreur PDOStatement::execute 值在同一请求中具有 WHERE 条件和 HAVING 条件
我如何在 WHERE、HAVING 这两个主题中执行准备值
$MyRequetteRecords = "
SELECT
_md_currencies._fd_currency,
(
SELECT GROUP_CONCAT( _md_tasks_level1._fd_name SEPARATOR ' + ') FROM _x_md_currencies_x_md_tasks
LEFT JOIN
_md_tasks AS _md_tasks_level1 ON
_x_md_currencies_x_md_tasks.ID_md_tasks = _md_tasks_level1.ID
WHERE _x_md_currencies_x_md_tasks.ID_md_currencies = _md_currencies.ID
) AS Many2Many_Currency
From
_md_currencies
WHERE
_md_currencies._fd_currency LIKE '% :value0 %'
HAVING
Many2Many_Currency LIKE '% :value1 %'
";
$ValueRequette=[
'value0' => 'Currency 1',
'value1' => 'Task'
];
$statement = $bdd_dataManger->prepare($MyRequetteRecords);
$statement->execute($ValueRequette);
$Record = $statement->fetchAll(\PDO::FETCH_ASSOC);
$statement->closeCursor();
错误:
参数编号无效:绑定变量的数量与标记的数量不匹配
您的 mysql 代码首先遇到问题 运行,因此您应该始终测试您的查询
WHERE _x_md_currencies_x_md_tasks.ID_md_currencies = _md_currencies.ID),"")
该行应该看起来像,因为列和 table 名称由点分隔,ifnull 还需要一个参数,所以您需要先关闭一个 brakcket
php 部分的错误首先是您使用单引号 alreadx 来确定字符串,因此在字符串内部使用它们是有问题的,因为您确实不需要它。
如您所见$ValueRequette=
您必须使用带双点的 palcehoders 名称
$MyRequetteRecords = '
SELECT `_md_currencies`.`_fd_currency`,
IFNULL(
(SELECT GROUP_CONCAT( _md_tasks_level1._fd_name SEPARATOR ' + ') FROM _x_md_currencies_x_md_tasks
LEFT JOIN
_md_tasks AS _md_tasks_level1 ON
_x_md_currencies_x_md_tasks.ID_md_tasks = _md_tasks_level1.ID
WHERE _x_md_currencies_x_md_tasks.ID_md_currencies = _md_currencies.ID),"")
AS Many2Many_Currency
From
`_md_currencies`
WHERE `_md_currencies`.`_fd_currency` LIKE :value0
HAVING Many2Many_Currency LIKE :value1
'
$ValueRequette=[
':value0' => '%' +'Currency 1'+'%' ,
':value1' => '%' +'Task'+'%'
]
我有一个 erreur PDOStatement::execute 值在同一请求中具有 WHERE 条件和 HAVING 条件
我如何在 WHERE、HAVING 这两个主题中执行准备值
$MyRequetteRecords = "
SELECT
_md_currencies._fd_currency,
(
SELECT GROUP_CONCAT( _md_tasks_level1._fd_name SEPARATOR ' + ') FROM _x_md_currencies_x_md_tasks
LEFT JOIN
_md_tasks AS _md_tasks_level1 ON
_x_md_currencies_x_md_tasks.ID_md_tasks = _md_tasks_level1.ID
WHERE _x_md_currencies_x_md_tasks.ID_md_currencies = _md_currencies.ID
) AS Many2Many_Currency
From
_md_currencies
WHERE
_md_currencies._fd_currency LIKE '% :value0 %'
HAVING
Many2Many_Currency LIKE '% :value1 %'
";
$ValueRequette=[
'value0' => 'Currency 1',
'value1' => 'Task'
];
$statement = $bdd_dataManger->prepare($MyRequetteRecords);
$statement->execute($ValueRequette);
$Record = $statement->fetchAll(\PDO::FETCH_ASSOC);
$statement->closeCursor();
错误: 参数编号无效:绑定变量的数量与标记的数量不匹配
您的 mysql 代码首先遇到问题 运行,因此您应该始终测试您的查询
WHERE _x_md_currencies_x_md_tasks.ID_md_currencies = _md_currencies.ID),"")
该行应该看起来像,因为列和 table 名称由点分隔,ifnull 还需要一个参数,所以您需要先关闭一个 brakcket
php 部分的错误首先是您使用单引号 alreadx 来确定字符串,因此在字符串内部使用它们是有问题的,因为您确实不需要它。
如您所见$ValueRequette=
您必须使用带双点的 palcehoders 名称
$MyRequetteRecords = '
SELECT `_md_currencies`.`_fd_currency`,
IFNULL(
(SELECT GROUP_CONCAT( _md_tasks_level1._fd_name SEPARATOR ' + ') FROM _x_md_currencies_x_md_tasks
LEFT JOIN
_md_tasks AS _md_tasks_level1 ON
_x_md_currencies_x_md_tasks.ID_md_tasks = _md_tasks_level1.ID
WHERE _x_md_currencies_x_md_tasks.ID_md_currencies = _md_currencies.ID),"")
AS Many2Many_Currency
From
`_md_currencies`
WHERE `_md_currencies`.`_fd_currency` LIKE :value0
HAVING Many2Many_Currency LIKE :value1
'
$ValueRequette=[
':value0' => '%' +'Currency 1'+'%' ,
':value1' => '%' +'Task'+'%'
]