无法在mysql数据库表中显示Android应用程序中插入的印地语值

时间:2014-08-15 07:55:08

标签: php android mysql

我正在使用php insert script

将hindi值插入mysql数据库

android插入代码

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 code

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

显示正确的单词'माऊली'

任何需要修改的线索?

1 个答案:

答案 0 :(得分:0)

得到了ans需要传递额外参数作为发送值我们需要将其编码为UTF8

 httpPost.setEntity(new StringEntity(body, HTTP.UTF_8));

感谢您的帮助:)。