我制作了一个应用程序,该应用程序将很少的文本输入从android发送到我的在线数据库.我的应用程序运行良好,但是一些用户报告说他们不能使用阿拉伯文字.所以我尝试了一下,当我在数据库中发送阿拉伯文本时,它显示为?????. ?????? ??????
我的PHP脚本:
$connect = mysql_connect($db_host,$db_uid,$db_pass) or die('could not connect');
mysql_select_db($db_name);
if(mysql_errno($connect))
{
die("Failed to connect to MySQL: " . mysql_error());
}
else
{
echo "success";
mysql_query("SET NAMES 'utf8'"); mysql_query('SET CHARACTER SET utf8');
}
$name = isset($_POST['name']) ? $_POST['name'] : '';
$sex = isset($_POST['sex']) ? $_POST['sex'] : '';
$nationality = isset($_POST['nationality']) ? $_POST['nationality'] : '';
$query = mysql_query( "insert into people (name, sex, nationality) values (N'$name' ,N'$sex', N'$nationality') ", $connect);
print_r($_POST);
if(!$query) echo mysql_error();
mysql_close($connect);
?>
我的Android代码:
DefaultHttpClient httpclient= new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.xxxxxxxx.com/thescript.php");
Log.e("done 1st","its here");
try
{
ArrayList nameValuePairs = new ArrayList();
nameValuePairs.add(new BasicNameValuePair("name", Name.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("sex", Sex.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("nationality", Nationality.getText().toString()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
Log.e("done", String.valueOf(response));
}
如您所见,我尝试了很少的东西,但没有一个起作用.
当使用插入到在线pc .php中时,我会得到这样的信息:
———
我的数据库设置为:
表排序规则是utf8_general_ci
?它的类型是MyISAM
以及其中的列(姓名,性别,国籍):
类型是varchar,排序规则是utf8_general_ci
例如
输出应该是???,但它是???