如何在Datamapper中使用Point或Geometry类型(codeigniter) [英] How to use a Point or Geometry type in Datamapper (codeigniter)
问题描述
我使用codeigniter和datamapper来构建API服务(在mysql上),其中一部分涉及地理位置 - 但我似乎无法找到使用点数据类型的解决方法。如果我尝试插入GeomFromText,系统会将它视为字符串。
任何人都可以帮忙吗?
干杯,
Mark。
如CodeIgniter用户指南中所述:
$ this-> db-> set();
set函数可让您为插入或更新设置值。
set()将接受第三个参数($ escape),如果设置为FALSE,将防止数据被转义。 code> $ this-> db-> set('geo',ST_GeomFromText('{$ data ['geo']}'),FALSE);
$ this-> db-> insert('tableName');
return $ this-> db-> insert_id()? $ this-> db-> insert_id():FALSE;
I'm using codeigniter and datamapper to build an API service (on mysql), and part of it involves geolocation - however I can't seem to find a workaround to use the point datatype. If I try to insert GeomFromText, the system treats it as a string.
Can anyone help?
Cheers, Mark.
As explained in the CodeIgniter User's Guide:
$this->db->set();
set function enables you to set values for inserts or updates.
set() will accepts a third parameter ($escape), that will prevent data from being escaped if set to FALSE.
$this->db->set('geo', "ST_GeomFromText('{$data['geo']}')", FALSE);
$this->db->insert('tableName');
return $this->db->insert_id() ? $this->db->insert_id() : FALSE;
这篇关于如何在Datamapper中使用Point或Geometry类型(codeigniter)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!