0

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.

enter image description here

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";
}       

}

Hasan Cheraghi
  • 867
  • 2
  • 11
  • 26

3 Answers3

0

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');
0

you can change the 'Collation' of column to 'utf8mb4_persian_ci' or 'utf8_persian_ci'.

it works.

Mohebbikhah
  • 53
  • 1
  • 9
-1

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']);

Nadir Latif
  • 3,690
  • 1
  • 15
  • 24