我非常熟悉CakePHP 2.0,但这是我还没有看到的。
我的模型试图运行本身不存在的函数。这只发生在Linux环境中,我仔细检查了文件名是否正确。我之前的情况与文件名不匹配。在Windows环境中,代码效果很好。
背景。我有早期的功能,名为“sql_version_xx”,他们只是运作良好,直到今天,版本33开始失败。 33以下的所有功能都像魅力一样。 33以上所有人都死于这个神秘的错误。我想这是一些愚蠢的错字,但我真的无法找到它。即使我重命名函数,错误仍然相同(我认为它有一些事情要做CakePHP样式将SqlVersion33转换为sql_version_33,反之亦然)。重命名没有帮助。
代码是为管理软件数据库更新而构建的,我们在此阶段有很多:D
有人能在这里听到拼写错误吗?
以下是案例的详细信息:
这是错误:
Database Error
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 'sql_version_33' at line 1
SQL Query: sql_version_33
Notice: If you want to customize this error message, create app/View/Errors/pdo_error.ctp
Stack Trace
CORE/Cake/Model/Datasource/DboSource.php line 460 → PDOStatement->execute(array)
CORE/Cake/Model/Datasource/DboSource.php line 426 → DboSource->_execute(string, array)
CORE/Cake/Model/Datasource/DboSource.php line 666 → DboSource->execute(string, array, array)
CORE/Cake/Model/Datasource/DboSource.php line 611 → DboSource->fetchAll(string, array, array)
CORE/Cake/Model/Model.php line 799 → DboSource->query(string, array, Installer)
APP/Model/Installer.php line 16 → Model->__call(string, array)
APP/Model/Installer.php line 16 → Installer->sql_version_33()
APP/Controller/InstallersController.php line 35 → Installer->Install(string)
[internal function] → InstallersController->install(string)
CORE/Cake/Controller/Controller.php line 490 → ReflectionMethod->invokeArgs(InstallersController, array)
CORE/Cake/Routing/Dispatcher.php line 187 → Controller->invokeAction(CakeRequest)
CORE/Cake/Routing/Dispatcher.php line 162 → Dispatcher->_invoke(InstallersController, CakeRequest, CakeResponse)
APP/webroot/index.php line 92 → Dispatcher->dispatch(CakeRequest, CakeResponse)
以下是型号的代码段:
<?php
App::uses('AppModel', 'Model');
App::import('Model', 'CContact');
class Installer extends AppModel {
public $useTable = 'c_event';
private $sql = array();
private $sql_indexes = array();
private $messages = array();
public function Install($version){
$this->sql = array();
$sql_function = 'sqlversion' . $version;
if(method_exists('Installer', $sql_function)) $this->$sql_function();
$string = '';
foreach($this->sql as $sql)
$string .= $sql . ';';
$dataSource = $this->getDataSource();
$dataSource->begin();
try{
if(strlen($string)>0)
$this->SqlQuery($string);
} catch(Exception $e){
$dataSource->rollback();
return array('exception' => $e->getMessage(), 'sql' => $this->sql);
}
$dataSource->commit();
}
以下是同一型号的几个功能:
public function sqlversion34(){
if(!array_key_exists('delay', $this->desc_table('k4_drafts')))
$this->sql[] = "ALTER TABLE k4_drafts ADD delay DATE NULL DEFAULT NULL";
if(!array_key_exists('remark', $this->desc_table('k4_drafts')))
$this->sql[] = "ALTER TABLE k4_drafts ADD remark DATE NULL DEFAULT NULL";
if(!array_key_exists('payday', $this->desc_table('k4_drafts')))
$this->sql[] = "ALTER TABLE k4_drafts ADD payday DATE NULL DEFAULT NULL";
}
public function sqlversion33(){
if(array_key_exists('payday', $this->desc_table('k4_drafts')))
$this->sql[] = "ALTER TABLE k4_drafts DROP payday";
}
public function sqlversion32(){
$this->sql[] = "ALTER TABLE k4_row_pen_intr CHANGE create_stamp create_stamp TIMESTAMP on update CURRENT_TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP";
}
如你所见。函数“sql_version_33”没有函数调用,但仍然收到此错误消息。
编辑:问题已解决
答案 0 :(得分:0)
从堆栈跟踪中,您的问题出在此处:
APP / Model / Installer.php第16行→安装程序 - > sql_version_33()
查看/ App / Model / Installer的第16行,查看该调用的内容。也许尝试将其更改为sqlversion33()。