0

I'm building a small project with Symfony 2.6. Its very simple with only one entity class which maps to data inserted into a MySQL database using python running on a Raspberry Pi.

Problem

when I run this simple repository query the result set is seemingly being converted to an array which is causing the an error (below). I'm not sure why this conversion is happening.

Repo method

public function getDataInRange( \DateTime $from, \DateTime $until)
{
    $query = $this->getEntityManager()->createQuery('
        select d
        from AppBundle:weatherdata d
        where d.idx > :f
        and d.idx < :u ')->setParameters(array( 'f' => $from, 'u' => $until      ));

    return $query->getResult();
}

Error

Catchable Fatal Error: Object of class DateTime could not be converted to string

Database structure

the main primary key, 'idx' is a datetime object, everything else is double.

Have tried..

I've tried altering the repo method to return getArrayResult() instead, which stops the error, but I need the result set to be in object format because of other messing about that I need to do to the data.

Thanks in advance.

DevDonkey
  • 4,835
  • 2
  • 27
  • 41

1 Answers1

-1
  1. U better use BETWEEN
  2. Convert the DateTime to a string

    $qb->where('e.fecha BETWEEN :monday AND :sunday') ->setParameter('monday', $monday->format('Y-m-d')) ->setParameter('sunday', $sunday->format('Y-m-d'));

please use the search, already answered here

Community
  • 1
  • 1
ToBe
  • 86
  • 4
  • Thats not what I'm asking. The query works fine, just returns an array set, not an object set. And yes, I did use search, but there are no solutions posted that have answered exactly right. – DevDonkey Feb 09 '15 at 20:44