gpt4 book ai didi

php - 将阿拉伯语文本从 Android 手机发送到在线 MySQl 数据库

转载 作者:可可西里 更新时间:2023-11-01 08:06:08 25 4
gpt4 key购买 nike

我制作了一个应用程序,它从 android 向我的在线数据库发送少量文本输入。我的应用程序运行良好,但一些用户报告说他们无法使用阿拉伯语文本。所以我尝试了,当我在数据库中发送阿拉伯语文本时,它显示为 ????? ???? ??????

我的 php 脚本:

<?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);
?>

我的安卓代码:

                DefaultHttpClient httpclient= new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.xxxxxxxx.com/thescript.php");
Log.e("done 1st","its here");

try
{
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
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));
}

如您所见,我尝试了一些方法,但都没有用。

当使用 insert into 使用在线 pc .php 我得到这样的:لببي

------------

我的数据库设置是:

表排序规则utf8_general_ci
并且它的类型MyISAM

和其中的列(姓名、性别、国籍):

typevarchar 并且 collat​​ionutf8_general_ci

例如输出应该是 علي 但它是 ???

最佳答案

这样做

DefaultHttpClient httpclient= new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.xxxxxxxx.com/thescript.php");
Log.e("done 1st","its here");

try
{
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
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, "UTF-8")); //UPDATE HERE
HttpResponse response = httpclient.execute(httppost);
Log.e("done", String.valueOf(response));
}

关于php - 将阿拉伯语文本从 Android 手机发送到在线 MySQl 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19009555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com