Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从数据库获取非英语语言的问题_Php_Android_Json_Api - Fatal编程技术网

Php 从数据库获取非英语语言的问题

Php 从数据库获取非英语语言的问题,php,android,json,api,Php,Android,Json,Api,我想把数据从PHP发送到Android手机。对于API调用,我使用“REST” 在我的PHP中,我所有的字符都是非英语语言(泰米尔语)。所以我使用utf-8在数据库中插入非英语(泰米尔语)内容 所有字符都插入到数据库中,我将数据作为json发送到Android。但我在Android开发方面的问题是,在获取json文件时,他们获取的所有字符都像问号(?????) 我是这个领域的新手,我不知道如何解决这个错误 这是我使用的PHP脚本: <?php require_once 'DbCo

我想把数据从PHP发送到Android手机。对于API调用,我使用“REST”

在我的PHP中,我所有的字符都是非英语语言(泰米尔语)。所以我使用utf-8在数据库中插入非英语(泰米尔语)内容

所有字符都插入到数据库中,我将数据作为json发送到Android。但我在Android开发方面的问题是,在获取json文件时,他们获取的所有字符都像问号(?????)

我是这个领域的新手,我不知道如何解决这个错误

这是我使用的PHP脚本:

<?php 
    require_once 'DbConnect.php';

    mysql_query('SET character_set_results=utf8');
    mysql_query('SET names=utf8');
    mysql_query('SET character_set_client=utf8');
    mysql_query('SET character_set_connection=utf8');
    mysql_query('SET collation_connection=utf8_general_ci');    

    $response = array();


    if(isset($_GET['apicall'])){

        switch($_GET['apicall']){


            case 'question':

                // i am get lesson and chapter name as request from application side ,i will match lesson and chapter and send question 
                $lesson  = $_POST['lesson'];
                $chapter = $_POST['chapter'];

                if(!isset($lesson) || !isset($chapter)){
                    $response['error'] = true; 
                $response['message'] = 'key and values is empty (or) wrong';
                http_response_code(404); 
                    }



                if(isTheseParametersAvailable(array('lesson','chapter'))){
                    //getting values 
                 $lesson = $_POST['lesson'];
                 $chapter = $_POST['chapter']; 

                    //creating the query 


                 $result1 = mysqli_query($conn, $query1);

                  $query = "SELECT que_desc,true_ans FROM question WHERE lesson = '".$lesson."' AND chapter = '".$chapter."' ";

                    $result = mysqli_query($conn, $query);
                   // $user =array();
                    $i=1;

                    while($row = mysqli_fetch_assoc($result))
                    {
                        $question = $row['que_desc'];
                        $true_ans = $row['true_ans'];
                        $response['question'][$i] = $question;
                        $response['ans'][$i] = $true_ans;

                        $i++;

                    }


                         mysqli_set_charset($link, 'utf8');


                         header('Content-Type: application/json');
                        echo json_encode($response , JSON_FORCE_OBJECT);
                        exit;


                }
            break; 



                default: 
                $response['error'] = true; 
                $response['message'] = 'Invalid Operation Called';
                http_response_code(404);

            }

    }else{
        //if it is not api call 
        //pushing appropriate values to response array 
        $response['error'] = true; 
        $response['message'] = 'Invalid API Call';
            http_response_code(404);
    }

    //displaying the response in json structure 
    header('Content-Type: application/json');
    echo json_encode($response);

    //function validating all the paramters are available
    //we will pass the required parameters to this function 
    function isTheseParametersAvailable($params){

        //traversing through all the parameters 
        foreach($params as $param){
            //if the paramter is not available
            if(!isset($_POST[$param])){
                //return false 
                return false; 
            }
        }
        //return true if every param is available 
        return true; 
    }

    if($_SERVER['REQUEST_METHOD'] ==  "GET"){
        $response['method_type'] = "wrong";
        $response['status'] = 0;
        http_response_code(404);

    header('Content-Type: application/json');
    echo json_encode($response);

    }


    ?>


请任何人帮我解决这个错误。提前感谢

当我试图通过谷歌解决上述问题时, 如果这是一个完整的php页面,每个人都被告知要使用下面的代码

    mysql_query('SET character_set_results=utf8');
    mysql_query('SET names=utf8');
    mysql_query('SET character_set_client=utf8');
    mysql_query('SET character_set_connection=utf8');
    mysql_query('SET collation_connection=utf8_general_ci'); 
如果是html页面,请使用

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
它在本地主机上工作

要使其在服务器中工作,请执行以下操作: 在BIGROCK服务器中,出于安全原因,他们阻止了一些文件,要求他们释放该文件。然后尝试上面的代码

因为在bluehost服务器中,上面的代码适用于我。 泰米尔语(非英语)内容以json格式显示良好,我将json发送给Andriod

在Bigrock服务器中也不适用。 希望这个能帮助别人

[mysqld]
init_connect='SET collation_connection = utf8_general_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake