首页 文章

非英语语言问题来自数据库

提问于
浏览
-2

我想将数据从PHP发送到Android手机 . 对于API调用,我正在使用“REST”

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

所有字符都插入到DB中,我将数据作为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);

    }


    ?>

This is my DB response on Android side任何人请帮我解决这个错误 . 提前致谢

1 回答

  • 0

    当我试图谷歌解决上述问题时,每个人告诉使用下面的代码,如果它是一个完整的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">
    

    当你使用php和html时,你必须实现mysql_query()函数代码和上面的元标记

    完成上述所有操作后,我还没有找到任何解决方案,工作几个小时后,要使其工作在localhost(xammp)1.go到xammp仪表板单击mysql配置文件2.file名称“my.ini”将打开粘贴下面的代码

    [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
    

    它在当地主办方工作

    使其在SERVER中工作:在BIGROCK SERVER中,出于安全原因,他们阻止了一些文件,要求他们释放文件 . 然后尝试上面的代码 .

    因为在bluehost Server上面的代码对我有用 . 泰米尔语(非英语)内容以json格式显示,我将json发送给Andriod,

    并且在Bigrock服务器中没有相同的功能 . 希望这个人可以帮助别人 .

相关问题