[英]the problem to save Persian data in MySQL database
I'm trying to save Persian data in MySQL.我正在尝试将波斯数据保存在 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');我为数据库中的排序规则设置了 utf8 通用 ci,还添加了 header('Content-Type: text/html; charset=utf-8'); in PHP file.在 PHP 文件中。 but show data like this image.但显示像这张图片一样的数据。
Users.php用户.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 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 connect时,必须设置
mysql_query("SET NAMES 'utf8'");
and for mysqli 对于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'.您可以将列的“排序规则”更改为“utf8mb4_persian_ci”或“utf8_persian_ci”。
it works.有用。
The data that you insert should have utf8 encoding. 您插入的数据应具有utf8编码。 You can encode the data using utf8_encode function. 您可以使用utf8_encode函数对数据进行编码。 For example: 例如:
$fullname = utf8_encode($_GET['fullname'])
; $fullname = utf8_encode($_GET['fullname'])
;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.