错误:SQLSTATE [42000]:语法错误或cakePHP的访问冲突

问题描述:

我正在为我的应用程序使用cakePHP框架.我使用xampp在localhost上对其进行了编程,现在尝试将其上传到我的网站上.它在localhost上没有任何问题.现在只有一页,在新服务器上不起作用.其他站点(也使用数据库连接)可以正常工作.

I am using the framework cakePHP for my application. I programmed it on localhost with xampp and try to upload it on my website now. It worked without any problems on localhost. Now there is only this one page, which does not work on the new server. The other sites (which use the database connection too) work alright.

对于该站点,将显示以下消息:

For this one site the following message appears:

错误:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法错误;查看与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的"add"附近使用

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 'add' at line 1

SQL查询:添加

函数add()看起来像这样.

The function add() looks like this.

public function add() { 
      //$this->create();
      $word_id = $this->Word->getWord_id();
      $save = $this->save(array('word_id' => $word_id, 'text' => $this->getText($word_id), 'mistake' => 0));
      return $save['Game']['id']; 
   }

在localhost上,我使用了MySQL-Client-Version:mysqlnd 5.0.8-dev-20102224-$ Revision:310735 $和PHP版本5.3.8.

On localhost I used MySQL-Client-Version: mysqlnd 5.0.8-dev - 20102224 - $Revision: 310735 $ and PHP Version 5.3.8.

在服务器上,我使用MySQL-Client-Version:5.1.62和PHP版本5.3.17.

On the server I use MySQL-Client-Version: 5.1.62 and PHP Version 5.3.17.

非常感谢您的帮助!

模型游戏":

class Game extends AppModel {
   public $name = 'Game';
   public $belongsTo = 'Word';
   public $searchedWord = '';

   public function addGame() { // Create new game
      $word_id = $this->Word->getWord_id();
      $save = $this->save(array('word_id' => $word_id, 'text' => $this->getText($word_id), 'mistake' => 0));
      return $save['Game']['id']; // Build the hangman
    }
}

当我调试$ this-> Game时,输出为:

When I debug $this->Game, the output is:

object(AppModel) {
        useDbConfig => 'default'
        useTable => 'games'
        id => null
        data => array()
        schemaName => null
        table => 'games'
        primaryKey => 'id'
        validate => array()
        validationErrors => array()
        validationDomain => null
        name => 'Game'
        alias => 'Game'
        tableToModel => array(
            'games' => 'Game'
        )
        cacheQueries => false
        belongsTo => array()
        hasOne => array()
        hasMany => array()
        hasAndBelongsToMany => array()
        actsAs => null
        Behaviors => object(BehaviorCollection) {
            modelName => 'Game'
            defaultPriority => (int) 10
        }
        whitelist => array()
        cacheSources => true
        findQueryType => null
        recursive => (int) 1
        order => null
        virtualFields => array()
        __backAssociation => array()
        __backInnerAssociation => array()
        __backOriginalAssociation => array()
        __backContainableAssociation => array()
        findMethods => array(
            'all' => true,
            'first' => true,
            'count' => true,
            'neighbors' => true,
            'list' => true,
            'threaded' => true
        )
}

通常,如果发生此错误,则您没有模型实例,但是您正在使用的应用程序模型实例.该应用程序模型实例没有add()方法,而是直接使用add()查询数据库.

usually, if this error happens, you don't have the model instance, but an app model instance you work on. the app model instance doesnt have the add() method and directly queries the db with add().

,因此请确保正确包含您的模型.因为您没有向我们展示代码,您如何调用该方法(以及如何使模型对控制器可用),但是我无法提供任何具体建议.

so make sure your model is properly included. since you didnt show us the code how you call the method (and how you make the model available to the controller) I cannot offer any concrete advice, though.

如果您手动添加它:

$this->ModelName = ClassRegistry::init('ModelName');