【问题标题】:Strange behaviour with Doctrine_Query in Doctrine 1.2Doctrine 1.2 中 Doctrine_Query 的奇怪行为
【发布时间】:2013-04-17 03:32:27
【问题描述】:

我有一个包含多个 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”一词引起问题。没有任何改变。

尽管我插入与直接输入完全相同的数据作为绑定参数,但行为发生了巨大变化。这到底是怎么回事?

【问题讨论】:

    标签: php doctrine-1.2 doctrine-query


    【解决方案1】:

    我想说$districtIds var 的值中一定有一些东西会绊倒 Doctrine 中的查询构建器。你能发布一个这些值是什么的样本吗?

    此外,您是否查看过学说运行的生成 SQL(跟踪 SQL 日志或挂钩到 preExecute 事件)?我很想看看这样的输出。

    (这应该是一个评论,但我的声誉还不够高;))

    【讨论】:

    • 它们只是整数值。
    猜你喜欢
    • 2012-02-15
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-06
    相关资源
    最近更新 更多