MySQL错误......#1305

时间:2011-07-22 14:12:41

标签: php mysql cakephp

当我通过Cakephp中的控制器查询MySQL查询时,我发生了以下错误。

SELECT id, 6371 * ACos(COS(RADIANS(users.latitude)) * Cos
                        (RADIANS(35)) * Cos(RADIANS(33) - RADIANS
                        (users.longitude)) + Sin(RADIANS(users.latitude)) * Sin
                        (RADIANS(35)) ) AS distance
                        FROM users
                        ORDER BY distance
                        LIMIT 20;

我被困在这里......有谁知道这个问题是什么?

Warning (512): SQL Error: 1305: FUNCTION wmetools_track.Cos does not exist [APP/cake/libs/model/datasources/dbo_source.php, line 684]
Code | Context

DboSource::showQuery() - APP/cake/libs/model/datasources/dbo_source.php, line 684
DboSource::execute() - APP/cake/libs/model/datasources/dbo_source.php, line 266
DboSource::fetchAll() - APP/cake/libs/model/datasources/dbo_source.php, line 410
DboSource::query() - APP/cake/libs/model/datasources/dbo_source.php, line 287
Model::query() - APP/cake/libs/model/model.php, line 2463
UsersController::api_localusers() - APP/controllers/users_controller.php, line 88
Dispatcher::_invoke() - APP/cake/dispatcher.php, line 204
Dispatcher::dispatch() - APP/cake/dispatcher.php, line 171
[main] - APP/webroot/index.php, line 83

1 个答案:

答案 0 :(得分:2)

看起来MySQL不喜欢函数名和左括号之间的空格。

select cos    (0.4) -- error
select cos(0.4) -- works

编辑: MySQL Documentation支持此功能。但显然有一个解决方法:使用“IGNORE_SPACE”可以解决您的问题(仅仅是删除函数名称和左括号之间的空格)。