MySQL + PHP: How to handle Umlauts in Stored Proce

2019-09-21 01:21发布

问题:

I have this function in PHP:

public function getData($data) {
    echo $data; //param still right for example: Schärding
    $result = mysqli_query($this->conn, "CALL sp_kampagne_findcurrent ('".$data."')") or die(mysqli_error($this->conn));
    @mysqli_next_result($this->conn);
    return $result;
}

As you can see I pass the parameter $data to my SP and then I return the result.

The Problem here is that if I pass words without Umlauts (ä,ö,ü) it works perfect, but if im using words like "Schärding" it returns zero data, even if there is data stored in MySQL.

The weird thing is, if Im calling my SP directly in PHPmyAdmin it works with the Word "Schärding". So the error must be on PHP Client Side.

If you need some more Information just say it Ill try to add more.

回答1:

You should try adding

mysqli_set_charset to your code, once a mysqli connection is established

For example:

mysqli_set_charset($this->conn,"utf8");

Of course updating the encoding so it fits what you need



标签: php mysql encode