в моем репозитории у меня естьЗаявление в 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 не хватает
Что вы думаете об этом [http://www.doctrine-project.org/docs/dbal/2.2/ru/reference/data-retrieval-and-manipulation .html # doctrinedbaltypes-преобразования)? – rkmax
Да, проблема была кавычками в запросе – rkmax