Search code examples
phpodbc

PHP ODBC SQL special chars


I got an input to search people by name on my DB. This one calls an ajax which calls a php file who executes the query:

$sql = "Select * from table where name like '%Ñ%'";

return $this->queryODBC($sql);

This is running if I'm not using special chars like Ñ.

I've been debugging and as I can see SQL is ok.

But finally when the app gets to the query execution:

public function queryODBC($query) {
    $db = $this->connectSyBase();

    $results = new stdClass;

    $results = (array) $results;

    $result = odbc_exec($db, $query);

    while ($row = odbc_fetch_object($result)) {
        $results[] = $row;
    }
    odbc_close($db);

    return $results;
}

I'm getting 0 rows... I can imagine that is because of the Ñ, because if no special chars is working ok.


Solution

  • This actually works

    $sql = iconv('UTF-8','ISO-8859-1',$sql);