admin管理员组文章数量:1415421
I am trying to insert data which contains a POINT field. I am using the $wpdb->insert method but when generating the SQL it is wrapping the POINT in quotes.
global $wpdb;
$table = $wpdb->base_prefix . 'points';
$Data = array(
'Title' => $this->Title,
'gPoint' => sprintf("POINT(%s,%s)",$this->Lng, $this->Lat),
'Lat' => $this->Lat,
'Lng' => $this->Lng
);
if (!$wpdb->insert($table,$Data))
throw new Exception($wpdb->last_error);
This is the SQL generated. If I take the quotes from around the POINT field, the query will run.
INSERT INTO `wp_points` (`Title`, `gPoint`, `Lat`, `Lng`) VALUES ('My Marker', 'POINT(0.2566251,51.0581515)', '51.0581515', '0.2566251')
Is there a way round this?
I am trying to insert data which contains a POINT field. I am using the $wpdb->insert method but when generating the SQL it is wrapping the POINT in quotes.
global $wpdb;
$table = $wpdb->base_prefix . 'points';
$Data = array(
'Title' => $this->Title,
'gPoint' => sprintf("POINT(%s,%s)",$this->Lng, $this->Lat),
'Lat' => $this->Lat,
'Lng' => $this->Lng
);
if (!$wpdb->insert($table,$Data))
throw new Exception($wpdb->last_error);
This is the SQL generated. If I take the quotes from around the POINT field, the query will run.
INSERT INTO `wp_points` (`Title`, `gPoint`, `Lat`, `Lng`) VALUES ('My Marker', 'POINT(0.2566251,51.0581515)', '51.0581515', '0.2566251')
Is there a way round this?
Share Improve this question asked Aug 29, 2019 at 15:56 StripyTigerStripyTiger 2771 silver badge6 bronze badges1 Answer
Reset to default 0If you use the %s
in your sprintf statement, $wpdb->insert() will automatically apply single-quotes.
You want to use %f
for float, or %d
for int/digit.
本文标签: databaseInserting data with Geometry field
版权声明:本文标题:database - Inserting data with Geometry field 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745200654a2647352.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论