怎么来MySQL位数据类型php打印unicode? [英] how come MySQL bit data type php print unicode?

查看:103
本文介绍了怎么来MySQL位数据类型php打印unicode?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的MySQ1数据类型是位(1),但是当打印php json_encode 将使用unicode写入IIS正常工作,

,但在我的专用服务器Apache托管将成为unicode。为什么?



你可以看到定位在Mysql数据类型上查找是位,但打印\\\?为什么?



这是我的编码GET方法 get-googlemarker.php 得到这个结果

 <?php 
mysql_connect(localhost,root,123456)或死(无法连接 ;
mysql_select_db(db_gps)或die(无法选择数据库);

$ parent_id = $ _GET ['mainid'];

$ query =SELECT *
FROM tbl_locate AS a
INNER JOIN

SELECT MainID,Max(DateTime)AS DateTime
FROM tbl_locate
GROUP BY MainID
)AS b
ON a.MainID = b.MainID
AND a.DateTime = b.DateTime
LEFT JOIN

SELECT b.PicData
,b.PicUploadedDateTime
,b.MainID
FROM(SELECT MainID,Max(PicUploadedDateTime)as PicUploadedDateTime
FROM tbl_picture
group by MainID
)l
JOIN tbl_picture b
ON b.MainID = l.MainID AND b.PicUploadedDateTime = l.PicUploadedDateTime
)AS c
ON a。 MainID = c.MainID;

$ rs = mysql_query($ query);

$ arr = array();
while($ obj = mysql_fetch_object($ rs)){
$ arr [] = $ obj;
}

echo json_encode($ arr);


?>



更新



表示数据正确,但问题是当我使用下面的javascript我无法读取定位值,
i已尝试 alert 的记录,但是blank.i已尝试定位与类型:string type:bit type:bytes type:int

但不起作用。不能在 alert中显示任何内容

  Ext.define('GoogleMarkerModel ',{
extends:'Ext.data.Model',
fields:[
{name:'ID',type:'int'},
{name:'定位',键入:'int'},
{name:'MainPower',type:'int'},
{name:'Acc',type:'int'},
{name:'PowerOff',type:'int'},
{name:'Alarm',type:'int'},
{name:'Speed',type:'int'
{name:'Direction',type:'int'},
{name:'Latitude',type:'float'},
{name:'Longitude',type: float'},
{name:'DateTime',type:'datetime'},
{name:'MainID',type:'int'},
{name:'IOState' ,键入:'int'},
{name:'OilState',键入:'int'},
{name:'PicUploadedD ateTime',键入:'datetime'},
{name:'PicData',键入:'str'}
]
});


解决方案

变量的呈现仍然正确。 p>

自PHP 5.4起,您可以使用 JSON_UNESCAPED_UNICODE json_encode()
请参阅 http://php.net/manual/en/function。 json-encode.php



我的猜测是,您的IIS默认返回未转义的值。



在Javascript中,您通常会使用 parseInt(\\\)或某些东西。
由于它是extjs,我不知道。



计划B:



A)将数据库列从位更改为整数。



B)将数据库值放在php中

  while($ obj = mysql_fetch_object($ rs)){
$ obj->定位=(int)$ obj-定位;
//或尝试(string)if(int)failed
$ arr [] = $ obj;
}

C)简单的 str_replace 在json输出中:

  $ json = json_encode($ arr); 
$ json = str_replace('\\\','1',$ json);
$ json = str_replace('\\\','0',$ json);


When my MySQl Data Type is bit(1) ,but when printed with php json_encode will write with unicode? IIS are working fine,
but in my dedicated server Apache hosting will become unicode. WHY?

you can see the Locating, Locating on Mysql data type is bit, but printed \u0001? why?

this is my coding GET method get-googlemarker.php to get this result

<?php
mysql_connect("localhost", "root", "123456") or die("Could not connect");
mysql_select_db("db_gps") or die("Could not select database");

$parent_id = $_GET['mainid'];

$query = "SELECT        *
FROM          tbl_locate AS a
INNER JOIN     
(
    SELECT    MainID, Max(DateTime) AS DateTime
    FROM      tbl_locate
    GROUP BY  MainID
) AS b
ON            a.MainID = b.MainID
AND           a.DateTime = b.DateTime
LEFT JOIN     
(
    SELECT b.PicData
     , b.PicUploadedDateTime
     , b.MainID
  FROM (SELECT    MainID,Max(PicUploadedDateTime) as PicUploadedDateTime
        FROM      tbl_picture
        group by MainID
       ) l
  JOIN tbl_picture b
    ON b.MainID = l.MainID AND b.PicUploadedDateTime = l.PicUploadedDateTime
) AS c
ON            a.MainID = c.MainID";

$rs = mysql_query($query);

$arr = array();
while($obj = mysql_fetch_object($rs)) {
 $arr[] = $obj;
}

echo json_encode($arr);


?>

UPDATED

the representation data are correct, but the problem is when i m using below javascript i can't read the Locating value, i have tried alert the record, but is blank.i have tried Locating with type:string , type:bit , type:bytes , type:int ,
but does not work. can't show anything in alert

Ext.define('GoogleMarkerModel', {
        extend: 'Ext.data.Model',
        fields: [
        {name: 'ID',    type: 'int'},
        {name: 'Locating',    type: 'int'},
        {name: 'MainPower',    type: 'int'},
        {name: 'Acc',    type: 'int'},
        {name: 'PowerOff',    type: 'int'},
        {name: 'Alarm',    type: 'int'},
        {name: 'Speed',    type: 'int'},
        {name: 'Direction',    type: 'int'},
        {name: 'Latitude',    type: 'float'},
        {name: 'Longitude',    type: 'float'},
        {name: 'DateTime',    type: 'datetime'},
        {name: 'MainID',    type: 'int'},
        {name: 'IOState',    type: 'int'},
        {name: 'OilState',    type: 'int'},
        {name: 'PicUploadedDateTime',    type: 'datetime'},
        {name: 'PicData',    type: 'str'}
        ]
    });

解决方案

The presentation of the variable is still correct.

Since PHP 5.4, you can use the option JSON_UNESCAPED_UNICODE with json_encode(). See http://php.net/manual/en/function.json-encode.php

My guess is that your IIS is returning the unescaped value by default.

In Javascript you'd usually use parseInt(\u0001) or something. Since it is extjs, I don't know for that.

Plan B:

A) Change the database column from bit to integer.

B) cast the database value in php

while($obj = mysql_fetch_object($rs)) {
  $obj->Locating = (int)$obj-Locating;
  // or try with (string) if (int) fails
  $arr[] = $obj;
}

C) simply str_replace in the json output:

$json = json_encode($arr);
$json = str_replace('"\u0001"', '"1"', $json);
$json = str_replace('"\u0000"', '"0"', $json);

这篇关于怎么来MySQL位数据类型php打印unicode?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆