0
該查詢得到了很多的麻煩我:問題首先是由於括號SQLSTATE [HY093]:無效的參數號
/* Looking for a machine already attributed to a site:
* - Date_started is in the given period
* OR - Date_ended is in the giver period
* OR - Date_started is before the period's end AND date_ended is null
* AND - 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']).
'" AND "'
.$dsql->escape($this['date_ended']).
'"')
->where('date_ended BETWEEN "'
.$dsql->escape($this['date_started']).
'" AND "'
.$dsql->escape($this['date_ended']).
'"')
->where($tmp->_dsql()->andExpr()
->where('date_started < "'.$dsql->escape($this['date_ended']).'"')
->where('date_ended IS null')
)
)
->where('machine_id = '.$dsql->escape($this['machine_id']))
->where('id != '.$dsql->escape($this['id']))
)
->getOne();
地塊,這就是爲什麼有這麼多orExpr
和andExpr
。然後由於BETWEEN
阻止使用轉義值的地方($ field,$ cond,$ value)。
如果我不逃避價值,它的工作原理,但像往常一樣,我不應該信任數據。我知道我可以在$ dsql-> expr()中寫下完整的查詢,然後設置setCustom,但這不是使用如此出色的框架的關鍵。
編輯:
Additional information:
pdo_error: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound
mode: select
params:
query: select (select concat(`site`.`emplacement`, " (", (select `nom` from `region` where `site`.`region_id` = `region`.`id`), ")") `designation` from `site` where `site_machine`.`site_id` = `site`.`id`) `site`,`id`,`machine_id`,`site_id` from `site_machine` where ((date_started BETWEEN ":a" AND ":a_2" or date_ended BETWEEN ":a_3" AND ":a_4" or (date_started < ":a_5" and date_ended IS null)) and machine_id = :a_6 and id != :a_7)
THX不突出我缺乏反思的;)它的工作原理,但我很關心關於錯誤。我知道我不能在'arg,arg,arg'和直接dsql-> escape之間混合使用'normal'。但在這裏,我改變了一切,以dsql->轉義,我仍然得到了PDO錯誤 – Sluggogle
也許你可以添加$ dsql-> debug()併發布你的SELECT查詢哪個ATK生成? – DarkSide