UTF8 字符无法正确显示数据表和 yadcf

UTF8 characters not displaying properly with datatables and yadcf

我有一个 UTF8 格式的 mysql 数据库,我之前已经正确输出了字母,但无法使我的 php 使用 ajax 过程对数据表进行输出。我尝试了各种方法让 UTF8 显示,包括更改 headers、使用 mysql 函数和更改 json 编码函数,但我无法使其工作。请帮助我正确显示 UTF8 而不是 ?s.

我有:temps.php 我的服务器端处理脚本:

 <?php
 header("Content-Type: text/json; charset=utf-8");
 require( 'ssp.class.php' );
 $table = 'articles';
 $primaryKey = 'id';
 $columns = array(
      array( 'db' => 'title',           'dt' => 0  ),
    array( 'db' => 'description',  'dt' => 1  ));
 $sql_details = array(
 'user' => 'root', 'pass' => 'pass', 'db'   => 'test', 'host' =>      'localhost'
 );

 $db = SSP::db($sql_details);
.....


 if($clause !== ""){
  $whereAll[] = $clause;
  $_GET['columns'][$i]['search']['value'] = "";
 }}
 echo json_encode(
 SSP::complex( $_GET, $db, $table, $primaryKey, $columns, null, 
  (!empty($whereAll) ? implode(" AND ", $whereAll) : "")
  ));

我有:temp.html:我的 Javascript 函数(基于数据表和 yadcf)

$(document).ready(function(){
$("#example").dataTable({
    "responsive": true,
    "processing": true,
    "serverSide": true,
    "ajax": "scripts/temps.php",
    "columns": [
       // ID
       null,

       // Distributor
       null
       // Director

    ]
}).yadcf([
    // ID
    {
      column_number: 0 ,
      filter_type: "text",
      filter_reset_button_text: false
    },
    // Abstract
    {
      column_number: 1,
      filter_type: "text",
      filter_delay: 500,
      filter_reset_button_text: false
    },


]);
});

我有 temp.html 输出数据的地方:(已编辑,因为很多代码与问题无关)

 <!DOCTYPE html>
 <div>
 <head>

 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 <meta name="Description" CONTENT=""/>
     ..........
 <table id="example" class="table table-striped table-bordered table-condensed" cellspacing="0" width="100%">
  <thead>
     <tr>
        <th><div>One</div></th>
        <th><div>Two</div></th>

     </tr>
  </thead>
 </table>

抱歉问了这么长的问题;但是我还能更改什么以使 UTF8 正确显示在 html 页面上?我已经尝试了所有我能想到的变量和函数的组合;但不能让它发挥作用。也许有一个可以在某处应用的js函数?谢谢你的帮助。

编辑:SQL供参考的结构:

     CREATE TABLE IF NOT EXISTS `articles` (
    `id` int(11) NOT NULL,
    `title` varchar(300) CHARACTER SET utf8 DEFAULT NULL,
    `description` text CHARACTER SET utf8
 ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
 -- Dumping data for table `articles`
 INSERT INTO `articles` (`id`, `title`, `description`) VALUES
 (1, 'శ్రీనివాస్scddadas తామాడా', '新概念英语第asv'),
 (2, 'asda', 'asdవా'),
 3, 'sdfsadfsdf英语', 'sadf英');

您需要在 PDO 连接中强制 utf8 :

$db = SSP::db($sql_details);
$db->exec("set names utf8");

或者,尝试将其作为参数传递:

$sql_details = array(
  'user' => 'root', 
  'pass' => 'ryan', 
  'db'   => 'edata', 
  'host' => 'localhost', 
  'charset' => 'utf8' 
);

但这不适用于所有 PHP 版本。

PS:为什么将table字段设置为utf8类型,而table字符集设置为latin1

如果您已将所有列添加为 "UTF-8" 但问题仍然存在,请尝试此操作

在服务器端文件中添加这些行

mysql_query("SET character_set_client=utf8",$gaSql['link']);
mysql_query("SET character_set_connection=utf8",$gaSql['link']);
mysql_query("SET character_set_results=utf8",$gaSql['link']);