【问题标题】:Unable to get data in proper format无法以正确的格式获取数据
【发布时间】:2014-01-29 12:42:52
【问题描述】:

我无法从 MySQL 解析 PHP 中的数据。

这是我的代码

    <?php
     header('Content-Type: text/html; charset=utf-8');
     // array for JSON response
      $response = array();   

      echo 'भगवान';

      require_once __DIR__ . '/db_connect.php';

       // connecting to db
       $db = new DB_CONNECT();

       // get all products from products table
       $result = mysql_query("SELECT *FROM create_event") or die(mysql_error());

       // check for empty result
       if (mysql_num_rows($result) > 0) {
       // looping through all results
       // products node
       $response["create_event"] = array();

       while ($row = mysql_fetch_array($result)) {
           // temp user array
           $product = array();
        $product["id"] = $row["id"];
        $product["desc"] = $row["desc"];
        $text;

        array_push($response["create_event"], $product);
    }

    // success
    $response["success"] = 1;


    echo json_encode($response);
     } else {
    // no products found
    $response["success"] = 0;
    $response["message"] = "No products found";

    // echo no users JSON
    echo json_encode($response);
     }
?>

这是我的数据库,我已将所有排序规则设置为 utf-8 ci 格式,但仍然无法正常工作:

我已经尝试了所有可能的解决方案和在线帮助,浏览了热门帖子和答案,还设置了浏览器设置以支持印地语语言,但仍然在输出中显示 ? 标记。这是输出格式

    भगवान{"id":"1","desc":"???? ??????"}

【问题讨论】:

    标签: php mysql utf-8


    【解决方案1】:
    mysql_query('SET character_set_results=utf8');
    

    在连接到数据库之后或在使用任何 select 语句之前使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-01
      • 1970-01-01
      • 2021-07-26
      • 1970-01-01
      • 1970-01-01
      • 2016-11-17
      • 1970-01-01
      相关资源
      最近更新 更多