发送波斯语字符串到mysql [英] Send persian string to mysql

查看:56
本文介绍了发送波斯语字符串到mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将波斯语字符串发送到 mysql 数据库;但是它将数据保存为类似这样的%D8%AC%D8%AF%DB%8C%D8%AF" .英文字符串没问题.

I am trying to send Persian string to the mysql database;but it saves the data as something like this "%D8%AC%D8%AF%DB%8C%D8%AF" . English strings have no problem.

var new = $(this).val();
 $.ajax({
    url: '/url/' + new,
    type: 'GET',
    success: function () {
      window.location.href = window.location.href;
    }
  });

这是我的 php 代码.

 public function url($new){
$db = Db::getInstance();
  $db->insert("INSERT INTO table (column) VALUES ('$new')");}

如何解决此问题?

我的网址字符有问题.我发现,如果我使用post方法,它将得到解决.我正在使用MVC结构,我想在URL中包含一些波斯字符串.那么我该如何解决这个新问题呢??

There is something wrong with my url charachters. I found out that if I use the post method, it will be resolved. I am using MVC structure and I want to have some Persian strings in my url . so how can I resolve this new problem???...

推荐答案

在数据库中插入波斯语或阿拉伯语等Unicode字符之前,您需要在数据库连接上设置Utf-8字符集.

Before insert Unicode character like persian or arabic in database you need to set Utf-8 characterset on db connection.

public function url($new){
$db = Db::getInstance();
$db->exec('SET NAMES utf8');
  $db->insert("INSERT INTO table (column) VALUES ('$new')");}

为了防止出现任何问题,在创建存储波斯字符或其他unicode字符的数据库时,必须将数据库排序规则设置为utf8 general ci.

also for prevent any problem you must set database collation to utf8 general ci when creating databases that store persian characters or other unicode characters.

这篇关于发送波斯语字符串到mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆