SoldierCorp
SoldierCorp

Reputation: 7700

PDO: Like condition doesn't work using bindParam

well... why doesn't work this sql statement?

public function searchProfile() {

    $termino = $this->term;
    $termino = "%".$termino."%";

    $sql = "SELECT * FROM cat_perfiles WHERE UPPER(Nombre) LIKE UPPER(:term)";

    $result = $this->dbConnect->prepare($sql) or die ($sql);
    $result->bindParam(':term',$termino,PDO::PARAM_STR);

    $numrows = $result->rowCount();
    $jsonSearchProfile = array();

    if ($numrows > 0) {
        while($row = $result->fetch(PDO::FETCH_ASSOC)) {
            $jsonSearchProfile[] = array(
                'IdPerfil' => $row['Id'],
                'NomPerfil' => $row['Nombre'],
                'DesPerfil' => $row['Descripcion'],
                'EdoPerfil' => $row['Activo']
            );
        }
        $jsonSearchProfile['success'] = 'success';
        return $jsonSearchProfile;
    } else {
        return false;
    }
}

I check data from $this->term and is correct! But when compare with LIKE doesn't work.

I hope can help me!

Upvotes: 0

Views: 881

Answers (1)

Musa
Musa

Reputation: 97672

You forgot to execute the query

$result->execute();

Upvotes: 5

Related Questions