Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
DB: where escaping non integers
  • i need to do a DB query based on a distance from a point for that I use geo-coordinates as such $query->where ('SQRT(POWER(((latitude - (".$latitude."))*69.1),2) + POWER(((longitude - (".$longitude."))*69.1),2))"','<',100) I get a Fuel\Core\Database_Exception [ 1064 ] error with the value of $latitude , $longitude being escaped ( they r not integers ) as well as the "69.1" number I am using. any suggestions as to how to work around this? thank you
  • Escaped how? Got some examples of what is actually happening?
  • You need DB::expr(), check the docs. Everything wrapped in a Database_Expression isn't escaped.
  • Phil : this is what the error message looks like :
    : 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 '37`.`48`))*`69`.`1`),2) + POWER(((longitude - (-122`.`33))*69`.`1),2)) * 1` <= '' at line 1
    the complete line is here :
    SQRT(POWER(((latitude - (`37`.`48`))*`69`.`1`),2) + POWER(((longitude - (-122`.`33))*69`.`1),2)) * 1` <= '10' ; Jelmer, thank you for pointing me in the right direction. update : It worked like a charm Jelmer. for those who need more details :
    this is what it would look like at $distance = "SQRT(POWER(((latitude - (".$latitude."))*69.1),2) + POWER(((longitude - (".$longitude."))*69.1),2)); $query->where(DB::expr($distance),'<', 10);

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion