我正在使用php插入脚本将印地语值插入mysql数据库
android insert code
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("data1","माऊली"));
nameValuePairs.add(new BasicNameValuePair("data2","माऊली"));
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.mydemo.com/insert.php");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
insert.php代码
<?php
$host='100.111.111.11';
$uname='tempdata';
$pwd='tempdata';
$db="tempdata";
$con = mysql_connect($host,$uname,$pwd) or die("connection failed");
mysql_select_db($db,$con) or die("db selection failed");
$data1=$_REQUEST['data1'];
$data2=$_REQUEST['data2'];
$flag['code']=0;
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $con);
if($r=mysql_query("insert into test values('$data1','$data2') ",$con))
{
$flag['code']=1;
}
print(json_encode($flag));
mysql_close($con);
?>
插入成功,但值看起来像mysql数据库表
中的?????
如果相同的代码我执行如下'$r=mysql_query("insert into test values('माऊली','माऊली') ",$con)'
显示正确的单词'माऊली'
有什么需要修改的吗?
得到ans需要传递额外的参数作为发送值,我们需要将其编码为UTF8
httpPost.setEntity(new StringEntity(body, HTTP.UTF_8));
谢谢你的帮助