Mysql Json_encode在尝试连接两个数据库时生成空值

Mysql Json_encode在尝试连接两个数据库时生成空值,mysql,json,Mysql,Json,我已经使用utf8_unicode_ci对我的两个数据库的所有字段进行排序。对于英语和数字来说是不错的,但是对于泰语它没有显示。它只显示空值。我尝试了很多方法,但仍然如此。但是如果我删除$dbh2,这是完美的工作,但我需要两者 <?php $timezone = "Asia/Bangkok"; if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone); $dbh1

我已经使用utf8_unicode_ci对我的两个数据库的所有字段进行排序。对于英语和数字来说是不错的,但是对于泰语它没有显示。它只显示空值。我尝试了很多方法,但仍然如此。但是如果我删除$dbh2,这是完美的工作,但我需要两者

<?php    
$timezone = "Asia/Bangkok";  
if(function_exists('date_default_timezone_set')) date_default_timezone_set($timezone);

$dbh1 = mysql_connect('localhost','user1','pass1', true);
$dbh2 = mysql_connect('localhost','user2','pass2', true);

mysql_query("SET NAMES 'utf8");
mysql_select_db('DB1', $dbh1); 
mysql_select_db('DB2', $dbh2);

$name=$_GET['name'];
$data=array();

$search=mysql_query("SELECT * FROM `users` WHERE `uname` = '".$name."'",$dbh2);


    while($a=mysql_fetch_assoc($search))
    {
        $data[]=$a['total_point'];
    }  

    $find=mysql_query("SELECT * FROM  `item` order by `item_id` DESC",$dbh1);
     while($r=mysql_fetch_assoc($find))
     {
          $data[]=$r;
      }


     echo json_encode($data);

您的json以rogue
{
。删除它,它应该进行解析。您可以使用工具as来验证json的有效性。好的,我的初始答案似乎不是您的问题。我对您的实际问题感到困惑。
json\u encode
不返回NULL。失败时它将返回字符串或false。
json\u encode
适用于UTF-8编码数据,这意味着其他东西正在将您的utf-8编码数据转换为ASCII或其他没有这些字符的编码。请尝试改用utf-8编码,以便双方都知道您想使用utf-8。是的,它将以Null形式返回一些值。我打赌
var\u dump($data[0]['item\u detail'))
如果在json_encode.var_dump($data[0]['item\u detail'])之前回显,则为空。它显示的字符串(1)“0”为空,但我尝试在循环中回显$r,而它显示的是中文。
    [ "0",
        {
            "item_id": "10",
            "item_band": "Gift Card",
            "item_pic": "http://www.puncorp.com/Applications/GuruLotto/Lotto/card_04.png",
            "item_title": "Gift Card",
            "item_detail": null,
            "item_introduction": null,
            "item_point": "30000",
            "item_point_bg": "0",
            "item_available": "97",
            "item_rule": null,
            "item_expired": "30/12/2556",
            "item_confirm_deal": null,
            "item_confirm_use": null,
            "item_image_total": "10",
            "item_image1": "http://www.puncorp.com/Applications/GuruLotto/Lotto/card_04.png", 
            "status": "6"
        }
    ]