0

guys

I want to check in my database that is there any similar version. Now, if I'm running the sql statement in the mysql it gives me back results unfortunately the script below will return FALSE. The function receives the proper $var i already checked it with var_dump().

Any help would be greatly appreciated .

public function checkForSimilarities($var)
{
    $sql = new \Zend\Db\Sql\Sql($this->getAdapter());
    $select = $sql->select()
    ->from($this->tableName)
    ->where("version LIKE '%$var%'");

    $stmt = $sql->prepareStatementForSqlObject($select);
    $results = $stmt->execute();
    return $this->hydrate($results);
}

public function hydrate($results)
{
    $szamla = new \Zend\Db\ResultSet\HydratingResultSet(
            $this->hydrator,
            $this->entityPrototype
    );

    return $szamla->initialize($results);
}
Wermerb
  • 1,039
  • 3
  • 15
  • 30
  • possible duplicate of [like in where query in zend framework 2](http://stackoverflow.com/questions/15574025/like-in-where-query-in-zend-framework-2) – Crisp May 16 '14 at 14:47

1 Answers1

0

Just use Zend's like method in conjunction with the where method. For example:

$select->columns($columns)
       ->where->like('version', "%$var%");

       // example of using OR with "like" in case you ever need it
       // ->where->OR->like('name', '%'. $s .'%');

Pretty sure you can find more info on it in the ZF2 docs: http://framework.zend.com/manual/2.0/en/modules/zend.db.sql.html#like-identifier-like

alex
  • 602
  • 4
  • 7