I'm trying to save Persian data in MySQL. but when saved in database show like below image. I set utf8 general ci for collation in database and also add header('Content-Type: text/html; charset=utf-8'); in PHP file. but show data like this image.
Users.php
public function updateuser(){
if(isset($_GET['phone']) && isset($_GET['fullname']) && isset($_GET['userPhone']) && isset($_GET['citycode']) && isset($_GET['useraddress']) && isset($_GET['userstatus'])){
$phone = $_GET['phone'];
$fullname = $_GET['fullname'];
$userPhone = $_GET['userPhone'];
$citycode = $_GET['citycode'];
$useraddress = $_GET['useraddress'];
$userstatus = $_GET['userstatus'];
$query = "CALL sp_update_user('$phone','$fullname','$userPhone',$citycode,'$useraddress',$userstatus)";}
$dbcontroller = new DBController();
$this->users = $dbcontroller->executeupdateuserQuery($query);
return $this->users;
}
DBController.php
function executeupdateuserQuery($query) {
mysqli_set_charset($conn,'utf8');
$result = mysqli_query($this->conn,$query);
if ($result)
{
return "user_updated";
}else{
return "failed_updated";
}
}
when you run mysql connect , you must set
mysql_query("SET NAMES 'utf8'");
and for mysqli
$mysqli->set_charset("utf8")
full example:
$connect = mysql_connect($this->hosttype,$this->dbusername,$this->dbpassword)or die('error');
mysql_query("SET NAMES 'utf8'");
$select = mysql_select_db($this->dbname,$connect)or die('error');
you can change the 'Collation' of column to 'utf8mb4_persian_ci' or 'utf8_persian_ci'.
it works.
The data that you insert should have utf8 encoding. You can encode the data using utf8_encode function. For example:
$fullname = utf8_encode($_GET['fullname'])
;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.