Cakephp2 FindBy语句中出现Sql错误,获得1064语法错误

时间:2016-12-07 23:15:06

标签: php mysql arrays cakephp

*编辑: f indBy,感谢那位纠正我的评论者“

所以我在Cakephp 2中运行一个服务器脚本来处理应用程序“Bonuses”区域中的信息。

 $objAccount = $this->Account->FindById($Bonus['Account']['id']);

关闭发送错误的确切代码。它在BonusesComponent中,否则可以工作。

</pre>Error: SQLSTATE[42000]: Syntax error or access violation: 1064 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 'FindById' at line 1
#0 /var/www/secondcake/lib/Cake/Model/Datasource/DboSource.php(436): PDOStatement->execute(Array)
#1 /var/www/secondcake/lib/Cake/Model/Datasource/DboSource.php(403): DboSource->_execute('FindById', Array)
#2 /var/www/secondcake/lib/Cake/Model/Datasource/DboSource.php(646): DboSource->execute('FindById', Array, Array)
#3 /var/www/secondcake/lib/Cake/Model/Datasource/DboSource.php(588): DboSource->fetchAll('FindById', Array, Array)
#4 /var/www/secondcake/lib/Cake/Model/Model.php(776): DboSource->query('FindById', Array, Object(Account))
#5 /var/www/secondcake/app/Controller/Component/BonusesComponent.php(525): Model->__call('FindById', Array)
#6 /var/www/secondcake/app/Controller/Component/BonusesComponent.php(525): Account->FindById('83')
#7 /var/www/secondcake/app/Console/Command/CronTradeBonusesShell.php(24): BonusesComponent->EndBonus(Array)
#8 /var/www/secondcake/app/Console/Command/CronTradeBonusesShell.php(10): CronTradeBonusesShell->EndTradeBonuses()
#9 /var/www/secondcake/app/Console/Command/cronBase.php(105): CronTradeBonusesShell->cronMain()
#10 /var/www/secondcake/lib/Cake/Console/Shell.php(389): CronBase->main()
#11 /var/www/secondcake/lib/Cake/Console/ShellDispatcher.php(177): Shell->runCommand(NULL, Array)
#12 /var/www/secondcake/lib/Cake/Console/ShellDispatcher.php(69): ShellDispatcher->dispatch()
#13 /var/www/secondcake/app/Console/cake.php(33): ShellDispatcher::run(Array)

继承堆栈跟踪。

只是补充一下,如果有人对为什么有任何想法,我会非常感激。 FindBy方法在整个应用程序中运行良好。

1 个答案:

答案 0 :(得分:0)

您的问题是因为您在函数调用中输入了错字。

CakePHP2使用魔术函数__call将任何调用映射到模型。如果您查看Model::__call,您可以看到它将函数名称发送到每个行为,以查看一个行为是否具有相应的函数。如果该函数不存在,则将其作为请求直接发送到数据源。

如果CakePHP2中的SQL错误带有与函数名称对应的查询,您可能需要直接检查是否错误输入了函数名称。