I have a web mapping application built on Bootleaf (Leaflet + Bootstrap). Using the leaflet Draw plugin the user can create a polygon on the map. I'd like to insert that polygon into a geometry field to an SQL Server 2012 using PHP. I have a field called Boundary with spatial type Geography in a table called tblProjects.
There are hard coded values here just to get things working. They'll come from a jQuery post once I have things on the server side ironed out.
<?php
include_once("connection.php");
$connectionInfo = array("Database"=>"$dbname", "UID"=>$user, "PWD"=>$pass);
$DBH = sqlsrv_connect($server, $connectionInfo);
if( !$DBH ) {
echo "Connection could not be established.<br />";
if( ($errors = sqlsrv_errors() ) != null) {
foreach( $errors as $error ) {
echo "SQLSTATE: ".$error[ 'SQLSTATE']."<br />";
echo "code: ".$error[ 'code']."<br />";
echo "message: ".$error[ 'message']."<br />";
}
}
}
$sql = "INSERT INTO tblProjects (ProjectID, Boundary) VALUES (1, geography::STGeomFromText( "POLYGON (-93.30388806760311 27.994401411046173, -94.62224744260311 33.37641235124676, -79.70281384885311 31.80289258670676, -93.30388806760311 27.994401411046173)",4326));";
$stmt = sqlsrv_query($DBH, $sql);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));
} else {
echo "SUCCESS!";
}
It doesn't like my geography type, and I'm not sure how to include it; here's the PHP error: