'Error inserting into SQL Server geometry field using PHP driver
Trying to update a geometry data type in SQL Server using PHP with the SQL Server driver.
No error with the following code in SQL Server Mgmt Studio:
update tbladdressorg set location = Geography::Point(33, 33, 4326) where addressid = 188356
Error with the following PHP code ("$sscon" is the SQL Server connection resource)
$rslt = sqlsrv_query($sscon, "update tbladdressorg set location = Geography::Point(33,33,4326) where addressid = 188356")
Error message:
[Microsoft][ODBC Driver 17 for SQL Server][SQL Server] A .NET Framework error occurred during execution of user-defined routine or aggregate "geography":
System.FormatException: 24201: Latitude values must be between -90 and 90 degrees
So, 33 is not between -90 and 90???????
Of course, eventually I need syntax to be like:
$updateqry = "update tbladdressorg set location = geography::Point(?, ?, 4326) where addressid = ?";
$updata = array($acct['shippinglongitude'], $acct['shippinglatitude'], $aborg['addressid']);
$rslt1 = sqlsrv_query($ssconn, $updateqry, $updata);
I've been trying all kinds of combinations, even attempted 'stringing' to try to use "Text" syntax (which reverses order of lat lon, uses a space between lon/lat, blah blah blah) - to no avail. Error is pretty much always the same.
Solution 1:[1]
The issue was not with the code above. There was a complex set of rules and obscure object instances that was difficult to follow. SOLID is religiously followed which made it difficult to actually see the comprehensive flow and logic of the whole functional chain.
Finally found the real issue buried down in something like the 5th object/method reference.
Apologies to those that lost time on this post.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Charlie |
