How to insert point data into mysql using PDO bindParam?

后端 未结 2 1444
孤城傲影
孤城傲影 2020-12-19 20:50

DETAILS

I\'d like to make use of mysql\'s spatial extension, so I am trying to store longitude and latitude in a mysql table of datatype POINT using

相关标签:
2条回答
  • 2020-12-19 21:27

    Note that parameterizing queries is not (simple) string replacement. In your code your query parameter is put in a string literal which will be kept untouched.

    Try this:

    $location = 'POINT(' . $latitude . " " . $longitude . ')';
    $sql = "INSERT INTO my_geodata SET location = PointFromText(:location)";
    
    0 讨论(0)
  • 2020-12-19 21:43

    Spatial extensions aren't designed for latitude and longitude yet, they are designed for Cartesian coordinates. The distance functions don't take into account the curvature of the earth so always give wrong results. Quite sad I know...

    0 讨论(0)
提交回复
热议问题