How MySQL MySQL data type prints unicode?

When is my data type MySQl bit (1), but when printing with php json_encode will write using unicode? IIS are working fine
but on my dedicated server, Apache hosting will become unicode. WHAT FOR? enter image description here

Can you see that Locating , Locating for the Mysql data type is bit, but printed \ u0001? why?

this is my GET method to encode 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 view data is correct, but the problem is that when I use javascript below, I can’t read the Locating value, I tried the alert record, but it is empty. I tried finding 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'} ] }); 
+4
source share
2 answers

The presentation of the variable is still correct.

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

I assume your default IIS returns an immutable value.

In Javascript, you usually use parseInt(\u0001) or something like that. Since these are extjs, I do not know for this.

Plan B:

A) Change the database column from bit to integer.

B) enter 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) just str_replace in json output:

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

Use mysqlnd (native driver) for php. If you are on ubuntu:

 sudo apt-get install php5-mysqlnd sudo service apache2 restart 

The native driver returns integer types.

this method will only work for PDO (not mysqli).

0
source

Source: https://habr.com/ru/post/1494823/


All Articles