0
在我的仓库,我有声明中Doctrine2
public function findAllMorosos($date = 'now')
{
$datetime = new \Datetime($date);
$stmt = $this->getEntityManager()
->getConnection()
->prepare(self::sql_morosos);
$stmt->bindValue(':fecha', $datetime, 'datetime');
if ($stmt->execute()) {
return $stmt;
}
return null;
}
我的SQL查询是
-- SQL
select p.* from inf_pago p
join inf_venta v on v.id = p.venta_id
join inf_cliente c on c.id = v.cliente_id
where p.fecha_pago < ':fecha'
and DATEDIFF(':fecha', p.fecha_pago) >= 30
and p.saldo_por_pagar != 0
当我执行$repository->findAllMorosos()
我得到空数组(预计1行),查询是罚款。
当我尝试:
public function findAllMorosos($fecha = 'now')
{
$datetime = new \Datetime($fecha);
$stmt = $this->getEntityManager()
->getConnection()
->prepare(str_replace(':fecha', $datetime->format('Y-m-d'), self::sql_morosos));
if ($stmt->execute()) {
return $stmt;
}
return null;
}
工作正常。
能解释一下什么是错的bindValue
方法documentation和more docs不够
你怎么看[this](http://www.doctrine-project.org/docs/dbal/2.2/en/reference/data-retrieval-and-manipulation的.html#doctrinedbaltypes转换)? – rkmax 2012-01-10 17:21:39
是的问题是查询中的引号 – rkmax 2012-01-10 17:57:37