我如何用symfony / doctrine和odbc解决问题?

时间:2010-05-18 22:39:07

标签: php doctrine symfony-1.4

在遵循symfony教程(1.4.4)时,我收到ODBC / mssql 2008的错误。

  

SQLSTATE [07002]:COUNT字段不正确:0 [Microsoft] [SQL Server   Native Client 10.0] COUNT字段不正确或语法错误   (在ext \ pdo_odbc \ odbc_stmt.c:254处的SQLExecute [0])。查询失败:   “SELECT [j]。[id] AS [j__id],[j]。[category_id] AS [j__category_id],   [j]。[type] AS [j__type],[j]。[company] AS [j__company],[j]。[logo] AS   [j__logo],[j]。[url] AS [j__url],[j]。[position] AS [j__position],   [j]。[location] AS [j__location],[j]。[description] AS   [j__description],[j]。[how_to_apply] AS [j__how_to_apply],[j]。[token]   AS [j__token],[j]。[is_public] AS [j__is_public],[j]。[is_activated]   AS [j__is_activated],[j]。[email] AS [j__email],[j]。[expires_at] AS   [j__expires_at],[j]。[created_at] AS [j__created_at],[j]。[updated_at]   AS [j__updated_at] FROM [jobeet_job] [j] WHERE([j]。[category_id] =   '2'和[j]。[expires_at]> ?)ORDER BY [j]。[expires_at] DESC“

我已将问题缩小到使用参数的行 public function getActiveJobs(Doctrine_Query $q = null) { if (is_null($q)) { $q = Doctrine_Query::create() ->from('JobeetJob j'); }

    //$q->andWhere('j.expires_at > \''.date('Y-m-d H:i:s', time()).'\'');<-- this works
    $q->andWhere('j.expires_at > ?', date('Y-m-d H:i:s', time())); //<-- this line has problem
    $q->addOrderBy('j.expires_at DESC');

    return $q->execute();
}

//$q->andWhere('j.expires_at > \''.date('Y-m-d H:i:s', time()).'\'');<-- this works $q->andWhere('j.expires_at > ?', date('Y-m-d H:i:s', time())); //<-- this line has problem $q->addOrderBy('j.expires_at DESC'); return $q->execute(); }

有人能指出我正确的方向吗? 感谢。

1 个答案:

答案 0 :(得分:0)

我“解决了”改变为

$q->andWhere('j.expires_at >=?', date('Y-m-d H:i:s' time()));

它是一个临时解决方案,现在可以使用,但我想知道为什么它不适用于&gt;。 感谢