gpt4 book ai didi

PHP : how to use mysql prepare statement inside single quote

转载 作者:行者123 更新时间:2023-11-29 12:26:53 25 4
gpt4 key购买 nike

在我的 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

最佳答案

它的工作原理是这样的。

$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);

关于PHP : how to use mysql prepare statement inside single quote,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28184766/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com