0

尝试在 cakedc utils 插件中使用 cvdimport 行为时出现此错误。

语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“getImportErrors”附近使用正确的语法

这是导入功能

function import() {
$modelClass = $this->modelClass;
 if( $this->request->is('POST')) {
    $records_count = $this->$modelClass->find('count');
    try {
        $this->$modelClass->importCSV($this->request->data[$modelClass]['CsvFile']['tmp_name']);
    }
    catch (Exception $e) {
        $import_errors = $this->$modelClass->getImportErrors();
        $this->set('import_errors', $import_errors);
        $this->Session->setFlash(__('Error Importing')."  ".$this->request->data[$modelClass]['CsvFile']['name'] ." ," . __('column name mismatch.'));
        $this->redirect(array('action' => 'import'));
   }
   $new_records_count = $this->$modelClass->find('count') - $records_count;
   $this->Session->setFlash(__('Successfully Imported') . "  " . $new_records_count . 'records from' . $this->request->data[$modelClass]['CvsFile']['name']);
   $this->redirect(array('action' => 'index'));
}
$this->set('modelClass',$modelClass);
$this->render('../Common/import');
}//end import

以及位于公共目录中的视图文件

<h3>Import <?php echo Inflector::pluralize($modelClass); ?> from CSV data file</h3>
 <?php 
   echo $this->Form->create($modelClass, array('action' => 'import', 'type' => 'file'));
   echo $this->Form->input('CsvFile', array('label' => '', 'type' => 'file'));
   echo $this->Form->end('Submit');

?>

错误所在的行是: $import_errors = $this->$modelClass->getImportErrors();

有人可以向我指出导致错误的原因。我不知道要改变什么才能让它工作

4

1 回答 1

0

当您在模型上的方法调用中收到 SQL 错误时,这通常意味着未加载该行为。找出原因。

于 2014-12-21T21:15:50.823 回答