Home > Software design >  PDOStatement::execute Values doesn't work with WHERE Condition & HAVING Condition
PDOStatement::execute Values doesn't work with WHERE Condition & HAVING Condition

Time:11-29

i have a erreur PDOStatement::execute Values with WHERE Condition & HAVING Condition in same requette

how i can make execute preparing value in both of theme 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();

Erreur : Invalid parameter number: number of bound variables does not match number of tokens

CodePudding user response:

you first have a problem in your mysql code which would run, so you always should test your queries

WHERE _x_md_currencies_x_md_tasks.ID_md_currencies = _md_currencies.ID),"") sho9uld the line look like, as column and table name are separated by a dot and ifnull needs also a parameter, so you need to close one brakcket first

The errro in the php part, ist first that you use single quotes alreadx, to determine the string,so using them inside of the string is problematik, as you really don't need it.

As you see by $ValueRequette=You have to use the palcehoders name with the double points

$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' '%'  
]
  • Related