I am trying to insert some names in mysql database by using mysqli commands. The problem is whenever the Turkish character ü comes in text, the text in the database becomes just previous part of that character.
For example I try to insert : Humana Still Tee Anne Sütünü Arttıran Bitki Çayı
The text in database : Humana Still Tee Anne S
The column in database is a text column has utf-8 general_ci standards.
And these are my codes for inserting
function mysqli_connector()
{
$link = mysqli_connect(DB_HOSTNAME,DB_USERNAME,DB_PASSWORD,DB_DATABASE) or die("hata");
$link->set_charset("utf8");
mysqli_set_charset($link,"utf8");
return $link;
}
function oc_product_description($p_id,$name){
$link = mysqli_connector();
$link->query("insert into oc_product_description (product_id,name,language_id,meta_title)values('$p_id','$name','1','$name')")or die(mysqli_error($link));
mysqli_close($link);
}
oc_product_description(106,"Humana Still Tee Anne Sütünü Arttıran Bitki Çayı");
The problem occurs for ü letter i tried with other Turkish characters, it works fine.
Thanks for your time.
Characters Truncated Using Utf8 is usually caused by
- The client had accented characters encoded in latin1, and
SET NAMES utf8
was in effect during theINSERT
It does not matter what the
CHARACTER SET
is on the table and column; the problem occurs during the transfer to the server.
For example, here were the steps for INSERTing
é
:- The client had the
é
encoded as hexE9
, the latin1 encoding. - When transferring to the server,
SET NAMES utf8
said (incorrectly) "The bytes in the client are encoded as utf8". - But there is no utf8 character encoded
E9
, so the string is truncated before theE9
That is, the string is stored up to, but not including, the invalid encoding.
I have talked about
utf8
and latin1
, but many (not all) pairs of character sets suffer from this "truncation" problem.
The data cannot be recovered from the table.
Going forward, the fix is to have these agree:
- the encoding of the characters in the client
- the declared encoding in
SET NAMES
(or equivalent)
Note that it does not matter what the target column's
CHARACTER SET
is; the purpose of SET NAMES
is to convert between what the client has and what the column has. However, it is generally good to use utf8mb4 (or at least utf8) for all text.
0 comments:
Post a Comment