Suravi
Suravi

Reputation: 321

PHP : how to use mysql prepare statement inside single quote

In My PHP project I want to make prepare statement to insert point. I did it as fallows

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

but it shows following error message

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

What is the problem here? dl_location datatype is GEOMETRY

Upvotes: 0

Views: 563

Answers (1)

Suravi
Suravi

Reputation: 321

It work like this.

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

Upvotes: 1

Related Questions