簡體   English   中英

在Doctrine 1.2中使用Doctrine_Query的奇怪行為

[英]Strange behaviour with Doctrine_Query in Doctrine 1.2

我有一個包含多個orWhere語句的查詢。 PHP代碼如下所示:

$firstDay = $params['datetimeForMonth']->format('Y-m-d');
$lastDay = $params['datetimeForMonth']->format('Y-m-t 23:59:59');
$whereStatement = "(s.level = ?
    AND s.idForLevel IN (?) 
    AND s.startDatetime BETWEEN '$firstDay' AND '$lastDay')";
$q = Doctrine_Query::create()
    ->from('Mmb_Model_Schedule s')
    ->where($whereStatement, ['prefecture', $this->id])
    ->orWhere($whereStatement, ['district', $districtIds])
    ->orWhere($whereStatement, ['municipality', $municipalityIds])
    ->orWhere($whereStatement, ['workplace',    $workplaceIds])
    ->orWhere($whereStatement, ['user', $userIds]);

變量$ districtIds,$ municipalityIds,$ workplaceIds和$ userIds都提前定義為逗號分隔的值。

該查詢對每個級別(區域ID除外)都適用。 查詢中不會返回任何級別為“區”的記錄。

真正奇怪的是,如果我不使用綁定參數,而是插入以下代碼,則一切正常:

->orWhere("s.level = 'district' AND s.idForLevel IN ($districtIds) AND s.startDatetime BETWEEN '$firstDay' AND '$lastDay'")

更令人氣憤的是,如果我使用綁定參數,即使該查詢本身作為單個where語句(不包括所有其他語句)單獨完成,也不會給我任何幫助。

似乎還不夠,我什至嘗試將表從“ district”更改為“ prefDistrict”,以防萬一單詞“ district”引起了問題。 沒有改變。

盡管我像直接輸入時一樣將EXACT SAME數據作為綁定參數插入,但行為卻發生了巨大變化。 這到底是怎么回事?

我想說的是, $districtIds var的值中一定有某些東西使Toctrine中的查詢生成器崩潰。 您可以張貼這些值的樣本嗎?

另外,您是否看過了運行該理論的生成的SQL(拖尾SQL日志或掛接到preExecute事件)? 我很好奇看到這樣的輸出。

(這可能是一條評論,但是我的聲譽還不夠高;))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM