[TYPO3-mvc] $query->like() replaces operand with "?"

Jochen Rau jochen.rau at typoplanet.de
Mon May 31 14:36:00 CEST 2010


Hi Søren.

On 31.05.10 13:25, Søren Malling wrote:
> Hi,
>
> I got the following query object
>
>          public function findByTelephoneAndName($searchQuery) {
>                  $query = $this->createQuery();
>                  $query = $query->matching(
>                                          $query->logicalOr(
>
> $query->like('firstname', (string)'%'.$searchQuery.'%')
>                  #
> $query->like('lastname', '%'.$searchQuery.'%')
>                  #
> $query->like('telephone', '%'.$searchQuery.'%')
>                                          )
>                                  )->setLimit((integer) 10);
>                  return $query->execute();
>          }
>
> but no matter how I insert the $searchQuery variable the statement is
> returned as
>
> .... where fe_users.tx_ext_field LIKE ? ...
>
> even if I replace the variable with a static string.

I assume that you have debugged before the ? was replaced by the 
prepared value in line 225 of Typo3DbBackend. just uncomment line 226 to 
debug the statement.

The method logicalOr() expects two Constraints or an array of 
Constraints. You can also strip off "(string)" ans "(integer)":

$query = $this->createQuery();
$query = $query->matching(
     $query->logicalOr(
         array(
             $query->like('firstname', '%' . $searchQuery . '%'),
             $query->like('lastname', '%' . $searchQuery . '%'),
             $query->like('telephone', '%' . $searchQuery . '%')
         )
     )
);
$query->setLimit(10);
return $query->execute();


should work.

Regards
Jochen


More information about the TYPO3-project-typo3v4mvc mailing list