Level 1
Ok, found a way but I'm not sure if it's safe:
$bindings = [
sprintf('SRID=4326;LINESTRING(%s,%s,%s)','-120.2 38.5', '-120.95 40.7', '-126.453 43.252')
];
$path = DB::scalar("SELECT ST_AsEncodedPolyline(GeomFromEWKT(?))", $bindings);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
How to use query bindings for single quoted queries?
$path = DB::scalar("SELECT ST_AsEncodedPolyline(GeomFromEWKT('SRID=4326;LINESTRING(?,?,?)'))",[
'-120.2 38.5',
'-120.95 40.7',
'-126.453 43.252',
]);
Illuminate\Database\QueryException SQLSTATE[08P01]: <>: 7 ERROR: bind message supplies 3 parameters, but prepared statement "pdo_stmt_00000003" requires 0 (SQL: SELECT ST_AsEncodedPolyline(GeomFromEWKT('SRID=4326;LINESTRING(-120.2 38.5,-120.95 40.7,-126.453 43.252)'))).
Please or to participate in this conversation.