I have a weird problem happening:
I have a php page that compiles and executes a MySQL query to my web database. The goal is to try and determine if a point is within a polygon, using a custom non-MBR spatial relation function.
The query returns a syntax error result 1064.
Here is the echoed query that displays on my page:
SET @point = 'POINT(-63.610719000 44.669318000)'; SELECT * FROM `Zones` WHERE GISWithin(GeomFromText(@point), `zonePoly`) AND `zoneName` = 'trailerShareBoundary';
If I copy and paste that query string into phpMyAdmin, it works like a charm.
However, when the query originates from my php page, the following error is returned:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT * FROM `Zones` WHERE GISWithin(GeomFromText(@point), `zonePoly`) AND `zon' at line 1(1064)
And here is the php code that makes this all happen:
if(!is_null($lng) && !is_null($lat)){
//Create a mySQL variable to store a MySQL POINT object
$query= "SET @point = 'POINT(".$lng." ".$lat.")'; ";
//Test if the POINT variable is within the trailerShareBoundary variable using
//custom MySQL function
$query.= "SELECT * FROM `Zones` WHERE GISWithin(GeomFromText(@point), `zonePoly`) AND `zoneName` = 'trailerShareBoundary';";
echo "<br/>".$query."<br/>";
$result=mysqli_query($connection,$query);
var_dump($result);
echo '<br/>';
if(!$result==false){
$instructions = "<p>LOCK REQUEST VALID</p>";
}else{
$instructions = "<p>LOCK REQUEST INVALID</p>";
echo mysqli_error($connection) . "(" . mysqli_errno($connection) . ")";
}
echo $instructions;
}
I've figured out a work-around:
If I first query the database to create the @point variable, then create a SEPARATE QUERY to query the database with my SELECT statement, it magically works! Here's what I mean:
This works:
//Create a mySQL variable to store a MySQL POINT object
$query= "SET @point = 'POINT(".$lng." ".$lat.")'; ";
$result=mysqli_query($connection,$query);
echo "<br/>".$query."<br/>";
//Test if the POINT variable is within the trailerShareBoundary variable using
//custom MySQL function
$query= "SELECT * FROM `Zones` WHERE GISWithin(GeomFromText(@point), `zonePoly`) AND `zoneName` = 'trailerShareBoundary';";
$result=mysqli_query($connection,$query);
echo "<br/>".$query."<br/>";
So, can anyone tell me what's going on?