doctrine2 - SQL to QueryBuilder -


first, sorry bad english!

i try convert sql (it's operational):

select distinct u.id user u inner join detail de on u.id = de.id_user inner join matiere ma on u.id = ma.id_user de.ville = $var1 , ma.matiere = $var2 

in query builder. have try this:

$query = $repository->createquerybuilder('u.id')      ->from('user', 'u')      ->innerjoin('detail', 'de', 'with', ' u.id = de.id_user' )      ->innerjoin('matiere', 'ma', 'with', 'u.id = ma.id_user')      ->where('de.ville = :ville')      ->setparameter('ville', $ville)      ->andwhere('ma.matiere = :matiere')      ->setparameter('matiere', $matiere)      ->distinct(); 

but have error: "[syntax error] line 0, col 49: error: expected end of string, got '.' "

and when try this:

$query = $repository->createquerybuilder()     ->select('u.id')     ->from('user', 'u')     ->innerjoin('detail', 'de', 'with', ' u.id = de.id_user' )     ->innerjoin('matiere', 'ma', 'with', 'u.id = ma.id_user')     ->where('de.ville = :ville')     ->setparameter('ville', $ville)     ->andwhere('ma.matiere = :matiere')     ->setparameter('matiere', $matiere)     ->distinct(); 

i have error:

warning: missing argument 1 doctrine\orm\entityrepository::createquerybuilder(), 

i work doctrine , symfony3.

thanks help.

this syntax error , both function of development in query builder own instance of query , try make debug , see how sql query being built , syntax error possibly.

$qb = $repository->createquerybuilder(); $query = $qb->getquery(); $debug = $query->debug(); 

has space between strings [ ' u.id = de.id_user ' ) ] , remove these spaces try surround possible error;

or can try make way, work:

  $query = $repository->createquerybuilder(); <!--separte constructor line-->    $query->select('u.id')     ->from('user', 'u')     ->innerjoin('detail', 'de', 'with', 'u.id = de.id_user' ) <!--align line-->     ->innerjoin('matiere', 'ma', 'with', 'u.id = ma.id_user')     ->where('de.ville', ':ville') <!--separate line-->     ->setparameter('ville', $ville)     ->andwhere('ma.matiere', ':matiere') <!--separate line-->     ->setparameter('matiere', $matiere)     ->distinct()     ->getquery(); <!--add line-->      $resp = $query->getresult(); <!--get answer line--> 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -