Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect parameter count in the call to native function 'radians'

Tags:

php

mysql

trying to use a query to get the distance from a certain location utilizing this query. we have the distances/locations set up in a db already. here's the query:

$query = "SELECT *, ( 6371 * acos( cos( radians($lat) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians($lng) ) + sin( radians($lat) ) * sin( radians( lat ) ) ) ) AS distance 
FROM textloc HAVING distance < 20000 ORDER BY distance LIMIT 1;";

it keeps returning 'Incorrect parameter count in the call to native function 'radians' within the console. Obviously I'm doing something wrong here. any advice?

like image 799
dd47 Avatar asked Jan 09 '23 07:01

dd47


1 Answers

I know this is a late reply, but for all of you that are facing this issue:

This error means that the function is missing the parameter, in other words, it means that you are sending something like this to mysql

select radians();

This is not caused by a NULL nor caused by an empty value or by a missing column. In this situations radians() will return a different result:

select radians(NULL); #->returns NULL
select radians(''); #->returns 0
select radians(wrong_collumn); #->returns: Error Code: 1054. Unknown column 'wrong_collumn' in 'field list'

I hope this help out :)

like image 77
Miguel Costa Avatar answered Jan 18 '23 22:01

Miguel Costa