database - Inserting data with Geometry field

I am trying to insert data which contains a POINT field. I am using the $wpdb->insert method but when generating the

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

If 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745200655a4616305.html

相关推荐

  • database - Inserting data with Geometry field

    I am trying to insert data which contains a POINT field. I am using the $wpdb->insert method but when generating the

    12小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信