SQLSTATE[42000]: Syntax error or access violation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • manjava
    New Member
    • Sep 2009
    • 132

    SQLSTATE[42000]: Syntax error or access violation

    Hello,

    I do this Script the Doctrine on zend Framework 2

    Code:
    $qb = $entityManager->createQueryBuilder ();
    			$qb->select ( 'g' )->from ( 'Synchro\Entity\Group', 'g' )->where ( 'g.namegroup = :namegroup' )->setParameter ('namegroup', $nameGroup );
    			$query = $qb->getQuery ();
    			try {
    				$checkgroup = $query->getResult();
    				
    				if(!empty($checkgroup)){
    					
    					return $checkgroup[0]->getIdgroup();
    				}
    			} catch (\Doctrine\ORM\NoResultException $e) {
    				return null;
    			}
    I have this Error :

    SQLSTATE[42000]: Syntax error or access violation: 1064 Erreur de syntaxe près de 'group g0_ WHERE g0_.nameGroup = 'GroupPOUR TOUTE INFORMATION'' à la ligne 1
    How can i resolve This Issue ? Thanks In advance
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    group is part of the GROUP BY keyword and as such not a valid table name (unless you quote it correctly, but I don’t know how to tell Doctrine to do that).

    tl;dr "group" is a very bad choice for a table name

    Comment

    Working...