MySQL Error – ERROR:SQLSTATE[42000]: Syntax error or access violation: 1582 Incorrect parameter count in the call to native function ‘radians’

QuestionsCategory: CakephpMySQL Error – ERROR:SQLSTATE[42000]: Syntax error or access violation: 1582 Incorrect parameter count in the call to native function ‘radians’
Roboto asked 9 months ago

Getting MySQL Error –
ERROR:
SQLSTATE[42000]: Syntax error or access violation: 1582 Incorrect parameter count in the call to native function ‘radians’

When Running the SQL directly SQL QUERY , showing the same ERROR

 

Example, 
QUERY:
SELECT *, ( 3959 * acos( cos( radians($latitude) ) * cos( radians( latitude ) ) * cos( radians( longitude) - radians($longitude) ) + sin( radians($latitude) ) * sin( radians( latitude ) ) ) ) AS distance FROM cities_extended HAVING distance < 10 ORDER BY distance LIMIT 0 , 5;
devchandan Staff replied 9 months ago

Please Check the values in $latitude and $longitude

1 Answers
devchandan Staff answered 9 months ago


QUERY:
SELECT *, ( 3959 * acos( cos( radians($latitude) ) * cos( radians( latitude ) ) * cos( radians( longitude) – radians($longitude) ) + sin( radians($latitude) ) * sin( radians( latitude ) ) ) ) AS distance FROM cities_extended HAVING distance < 10 ORDER BY distance LIMIT 0 , 5;
** Please Check, Latitude & longitude Value.
For My Case, It was returning Null Value. So the DataBase was throwing MySQL error
$latitude = null;
$longitude = null;
If It Getting Null Value, change it to,
$latitude = 0;
$longitude = 0;