gpt4 book ai didi

php - Cakephp2 FindBy语句中的sql错误,得到1064语法错误

转载 作者:行者123 更新时间:2023-11-29 03:22:53 28 4
gpt4 key购买 nike

*编辑:findBy,感谢纠正我的评论者”

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

 $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 方法在整个应用程序中运行良好。

最佳答案

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

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

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

关于php - Cakephp2 FindBy语句中的sql错误,得到1064语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41029098/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com