Php 理论陈述2
在我的存储库中,我有Php 理论陈述2,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,在我的存储库中,我有 public function findAllMorosos($date = 'now') { $datetime = new \Datetime($date); $stmt = $this->getEntityManager() ->getConnection() ->prepare(self::sql_morosos); $stmt->bindValue(':fecha', $datet
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
很好
可以解释
bindValue
方法的错误,但还不够我认为问题实际上在您的sql字符串中。不要将参数占位符括在引号中。而且,我认为您需要不止一个占位符和绑定。将sql更改为:
where p.fecha_pago < :fecha1
and DATEDIFF(:fecha2, p.fecha_pago) >= 30
注意,doctrine使用它自己的语句bindValue实现,它将第三个参数(如果是字符串)映射到PDO参数int。这是我直到今天才意识到的:)你怎么看?是的,问题是查询中的引号
where p.fecha_pago < :fecha1
and DATEDIFF(:fecha2, p.fecha_pago) >= 30
$stmt->bindValue(':fecha1', $datetime, 'datetime');
$stmt->bindValue(':fecha2', $datetime, 'datetime');