Problem: Text get broken in MySQL.
A. Text is sent over webservice as below
$text = 'как дела';
$data = array(
'text' => $text,
'client' => 'abcd');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents(sms_url, false, $context);
if ($result === FALSE) {
}
return $result;
B. Controller receives the text and need to insert to MySQL:
$text = utf8_decode($_POST['text']);
$data = array(
'text' => $text,
);
$insert->values($data);
$selectString = $sql->getSqlStringForSqlObject($insert);
$adapter->query($selectString, Adapter::QUERY_MODE_EXECUTE);
MySQL column is utf8_general_ci (other language english no problem).
EDIT:
Before inserting to MySQL the data is showing in Russian correctly. But after insert into the MySQL the column shows like this: Терміновий
CodePudding user response:
The call to utf8_decode
is unessessary and is corrupting your text. It does not handle Russian, and it shouldn't be needed at all.
utf8_decode
per the manual "Converts a string with ISO-8859-1 characters encoded with UTF-8 to single-byte ISO-8859-1"
Russian characters are not contained in ISO-8859-1. If you run
echo utf8_decode('как дела');
outputs
??? ????
CodePudding user response:
Use utf8mb4_unicode_ci
as your column collation.