我有一个 mysql php pdo 语句,它有单引号来调用 Mysql Geolocation“POINT”函数。
$sql = "INSERT INTO userTrip
(userId, fromLat, fromLon, fromLoc, fromPOI,
toLat, toLon, toLoc, toPOI,
tripFinished, isMatched, departureTime, createdAt)
values
(:user,:fromLat,:fromLon, GeomFromText('POINT(:fromLat1 :fromLon1)'),:fromPOI,:toLat,
:toLon, GeomFromText('POINT(:toLat1 :toLon1)'),:toPOI,0,0,:departureTime,:date)";
$stmt = $db->prepare($sql);
$stmt->bindParam(':user', $userId, PDO::PARAM_INT);
$stmt->bindParam(':fromLat', $fromLat, PDO::PARAM_STR);
$stmt->bindParam(':fromLon', $fromLon, PDO::PARAM_STR);
$stmt->bindParam(":fromLat1", $fromLat, PDO::PARAM_STR);
$stmt->bindParam(':fromLon1', $fromLon, PDO::PARAM_STR);
$stmt->bindParam(':fromPOI', $fromPOI, PDO::PARAM_STR);
$stmt->bindParam(':toLat', $toLat, PDO::PARAM_STR);
$stmt->bindParam(':toLon', $toLon, PDO::PARAM_STR);
$stmt->bindParam(':toLat1', $toLat, PDO::PARAM_STR);
$stmt->bindParam(':toLon1', $toLon, PDO::PARAM_STR);
$stmt->bindParam(':toPOI', $toPOI, PDO::PARAM_STR);
$stmt->bindParam(':departureTime', $departureTime, PDO::PARAM_STR);
$stmt->bindParam(':date', date('Y-m-d H:i:s'), PDO::PARAM_STR);
当我执行查询时,它会引发异常“PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens”即使参数的数量是正确的。我怀疑单引号会引发查询,但我需要将它们放入。我尝试使用反斜杠以及我能想到的所有其他方式来转义它们,但查询不会执行。有没有解决的办法?