2017-09-23 29 views
2

我想從使用codeigniter的mysql數據返回用戶json。在MySQL中,我有一個列作爲點,當我調用mysql來獲取數據時,它看起來像這樣當我var_dump的信息。codeigniter從點獲取怪異符號

array(1) { [0]=> object(stdClass)#19 (10) { 
["ID"]=> string(1) "1" 
["contact_email"]=> string(25) "[email protected]" 
["owner_id"]=> string(1) "1" 
["point"]=> string(25) "}�#�[email protected]���ޯ�[email protected]" 
} 

因爲點,當我試圖JSON編碼和解碼,並將其發送給用戶,我得到NULL值。 我不知道如何解決這個問題,它是一個代碼問題或我如何設置我的數據庫。

CREATE TABLE `foo` (
    `ID` int(10) unsigned NOT NULL AUTO_INCREMENT, 
    `contact_email` varchar(100) NOT NULL, 
    `owner_id` int(100) NOT NULL, 
    `point` Point NOT NULL, 
    PRIMARY KEY (`ID`), 
    SPATIAL INDEX point_sx (`point`) 
) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARACTER SET utf8; 

這是插入語句看起來像

INSERT INTO foo (contact_email,owner_id, point) VALUES ('[email protected]', 1, POINT('60.168607847624095','24.932371066131623')); 

回答

0

更改你插入過程中,儘量將其插入類似下面,希望你會得到它的權利

$this->db->set("contact_email",'[email protected]'); 
$this->db->set("owner_id",1); 
$this->db->set("point",'geomfromtext("POINT(60.168607847624095,24.932371066131623)")',false); 
$this->db->insert("foo");