atk4 - SQLSTATE[HY093]: Invalid parameter number -


this query has been lot of trouble me:

/* looking machine attributed site:        *      - date_started in given period        *  or  - date_ended in giver period        *  or  - date_started before period's end , date_ended null        *  , - que l'on parle de la même machine        */                      $dsql = $tmp->_dsql(); $machine = $tmp->selectquery(array('site'))            ->where($dsql->andexpr()              ->where($dsql->orexpr()                ->where('date_started between "'                          .$dsql->escape($this['date_started']).                        '" , "'                          .$dsql->escape($this['date_ended']).                        '"')                 ->where('date_ended between "'                          .$dsql->escape($this['date_started']).                        '" , "'                          .$dsql->escape($this['date_ended']).                        '"')                ->where($tmp->_dsql()->andexpr()                  ->where('date_started < "'.$dsql->escape($this['date_ended']).'"')                  ->where('date_ended null')                )              )              ->where('machine_id = '.$dsql->escape($this['machine_id']))              ->where('id != '.$dsql->escape($this['id']))            )            ->getone(); 

lot of problems first due parentheses that's why there orexpr , andexpr. because of between prevents use where($field, $cond, $value) escape values.

if not escape values, works usual should not trust data. know wrote down full query in $dsql->expr() , setcustom not point of using such great framework.

edit:

additional information:  pdo_error: sqlstate[hy093]: invalid parameter number: no parameters bound mode: select params: query: select (select concat(`site`.`emplacement`, " (", (select `nom` `region` `site`.`region_id` = `region`.`id` ), ")") `designation` `site` `site_machine`.`site_id` = `site`.`id` ) `site`,`id`,`machine_id`,`site_id` `site_machine` ((date_started between ":a" , ":a_2" or date_ended between ":a_3" , ":a_4" or (date_started < ":a_5" , date_ended null)) , machine_id = :a_6 , id != :a_7) 

you can simplify conditions. should same wrote in question:

date_started < period_end , (date_ended null or date_ended >= period_start) 

and yes, no more between issue :)

if don't have lot of data, can , rid of or completely. keep in mind, ifnull(date_ended) not use indexes , work slower (check execution plan of select):

date_started < period_end , ifnull(date_ended, period_start) >= period_start 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -