PHP:如何在单引号内使用mysql prepare语句

时间:2015-01-28 04:43:10

标签: php mysql

在我的PHP项目中,我想制作插入点的准备语句。 我做了它作为休耕

$query = "update d_location set dl_location = GeomFromText('POINT(:lat :lon)') where dl_id = :id";
            echo $query;
            $stmt = $conn->prepare($query);
            $params = array(
                        'lat'=>$lat,
                        'lon'=>$lon,
                        'id'=>$d_id
                    );
            $stmt->execute($params);

但它显示以下错误消息

SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

这是什么问题? dl_location数据类型是GEOMETRY

1 个答案:

答案 0 :(得分:1)

它的工作原理如下。

$location = 'POINT(' . $lat . " " . $lon . ')';
            $query = "update d_location set dl_location = GeomFromText(:location) where dl_id = :id";
            $stmt = $conn->prepare($query);
            $params = array(
                        'location'=>$location,
                        'id'=>$d_id
                    );
            $stmt->execute($params);