Query with like returns nothing when it has more than one word in PHP

1

I'm trying to make a query using like in PHP and when I use one more than one word. Only works if I only put one word.
In SQL Server the query works without errors .

    <?php

 function listaMatHistOS($conn, $equipamento){
        $HistMatOS = array();
        $where = [];
        $where[] = "cliente.id = (select usuario.idCliente from usuario where usuario.login = '".usuarioLogado()."')";

        if ($equipamento) {
        $where[] = "material.nome like '%{$equipamento}%'";         
        }
        $SQL = "select os.id as IdOS, os.dataHora, material.nome as equipamento, itemMaterial.nSerie, itemMaterial.patrimonio, 
            itemMaterial.rm, os.status 
from os

inner join itemMaterial on
itemMaterial.id = os.id 

inner join material on
material.id = itemMaterial.idMaterial

inner join cliente on
cliente.id = os.idCliente

where " . implode(' AND ', $where) ;
        $resultado = sqlsrv_query($conn, $SQL);
        while ($RelMatOS = sqlsrv_fetch_array($resultado, SQLSRV_FETCH_ASSOC)){;
        array_push($HistMatOS, $RelMatOS);
    }
    echo $SQL;
    return $HistMatOS;
 }

    
asked by anonymous 29.11.2016 / 17:02

1 answer

1

Since the word without accent works correctly in the search the problem is probably the encoding used that for sqlsrv_query is ISO-8859-1 . So before running your query do decode :

$SQL = utf8_decode($SQL);

That will transform your UTF-8 to ISO-8859-1 .

    
29.11.2016 / 19:42