How to prepare SQL statement with POINT using mysqli when using INSERT

本小妞迷上赌 提交于 2019-12-19 11:55:09

问题


I can't seem to find where documented to successfully prepare a statement that uses the POINT data type.

This previous question (How to use POINT mysql type with mysqli - php) shows something marked as correct, but it doesn't work. I even tried using their simple query in their example:

$stmt = $this->conn->prepare("INSERT INTO days(day,POINT(lat,lon)) VALUES(?,?,?)");
$stmt->bind_param("sdd", $day, $lat, $lon);

This just simply returns and error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(lat,lon)) VALUES(?,?,?)' at line 1

回答1:


Try like below;

$stmt = $this->conn->prepare("INSERT INTO days(day,column_name) VALUES(?,POINT(?,?))"); //column_name is name of of column that you want to insert POINT(lat,lon)
    $stmt->bind_param("sdd", $day, $lat, $lon);
    $stmt->execute();


来源:https://stackoverflow.com/questions/43093902/how-to-prepare-sql-statement-with-point-using-mysqli-when-using-insert

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!