0

The following is my class with the method:

class BidsInfoRepository extends EntityRepository
{
     public function findbidWinnerQuery($productId) {
              return $this->getEntityManager()
                        ->createQuery("SELECT w FROM ReverseAuctionReverseAuctionBundle:BidsInfo w where w.ProductInfo = ***$productId*** GROUP BY w.bAmount HAVING COUNT(w) = 1")
                        ->setMaxResults(1)     
                        ->getResult() 
                ;
    }
}

The variable $productId has the following format value separated with hyphen: 5cbfde50-50b9-11e5-9612-752c7cea21e5 ,

Obviously it doesn't like that format in fact 'cbdfe50' is included in the string separated with hyphen and for some reason I think the hyphen stops the process, but I don't know how to let the mysql to process the long string separated with hyphen instead of returning the error mentioned on my issue title. Any idea? Thanks.

p.s. I've also tried using "like '$productId'" but it won't work.

armslegs
  • 1
  • 1
  • 4

1 Answers1

1

You simply forgot the quotes:

"SELECT w FROM ReverseAuctionReverseAuctionBundle:BidsInfo w where w.ProductInfo = '5cbfde50-50b9-11e5-9612-752c7cea21e5' GROUP BY w.bAmount HAVING COUNT(w) = 1"

Also keep in mind that you should properly escape strings in sql queries in order to avoid sql injection.

Lorenz Meyer
  • 19,166
  • 22
  • 75
  • 121