MySQL + PHP:如何在存储过程参数中处理Umlauts? [英] MySQL + PHP: How to handle Umlauts in Stored Procedure Params?
问题描述
我在PHP中具有以下功能:
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;
}
如您所见,我传递了参数 $ data
到我的SP,然后返回结果。
As you can see I pass the parameter $data
to my SP and then I return the result.
这里的问题是,如果我在不带文字的情况下不带 (ä,ö,ü
)可以完美运行,但是如果即时消息使用Schärding之类的单词,即使MySQL中存储了数据,它也会返回零数据。
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.
奇怪的是,如果我在 PHPmyAdmin
中直接调用我的SP 和Schärding一词。因此该错误必须在PHP客户端上。
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.
推荐答案
一旦建立mysqli连接,您应该尝试将
You should try adding
mysqli_set_charset
添加到代码中
例如:
mysqli_set_charset($this->conn,"utf8");
当然会更新编码,使其适合您的需求
Of course updating the encoding so it fits what you need
这篇关于MySQL + PHP:如何在存储过程参数中处理Umlauts?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!