Reputation: 63
I have a column with nickname that it's collection is utf8-general-ci
and table collection is UTF-8. But persian/arabic text stores in it like below.
https://i.sstatic.net/CCWOa.png
How should Solve this problem?
I use this code to save
$sql = "INSERT INTO kashef_users(nickname ,username ,email ,ostan ,age ,gender ,sdk ,phonename ,imei ,time ) VALUES ".$data;
$data
contains a a string and everything in data is correct
Upvotes: 2
Views: 3345
Reputation:
It seems you are using php
to populate $data
. So you have to set charset as UTF8
(i.e. SET NAMES 'utf-8';
). For example if you were using mysqli
, your code would be like this:
<?php
$conn = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
mysqli_set_charset($conn,"utf8");
Or use this answer if you were using PDO
or this one for deprecated mysql
. Moreover, do not forget to use utf8-persian-ci
collection.
In your html
if you have a form, set the accept-charset
as UTF-8
:
<form action="" accept-charset="UTF-8">
Upvotes: 6