错误:SQLSTATE [42S22]:未找到列:1054'where子句'中的未知列'dummy @ .books.id'

时间:2013-08-22 10:43:21

标签: cakephp cakephp-2.0

我在查找我从哪里收到此错误时遇到了一些问题:

  

错误:SQLSTATE [42S22]:未找到列:1054'where子句'中的未知列'dummy @ .books.id'

sql查询

UPDATE 
    `dummy@`.`books` 
SET 
    `isbn` = '1234532', 
    `title` = 'cakephp blog tutorial', 
    `id` = 5, 
    `description` = 'gh', 
    `author_name` = 'andrew' 
WHERE 
    `dummy@.books.id` = '5'

如果我编辑记录,则发生以下错误

控制器功能

function edit ($id = NULL){
         if (!$id && empty($this->request->data)) {
          $this->Session->setFlash('Invalid Book', true);
          $this->redirect(array('action'=>'index'));
       }  

        else {    
            $this->Book->create();

         $save = $this->Book->save($this->request->data);
            if($save){ 

               $this->Session->setFlash('book detail edit successfully');
               $this->redirect(array('action'=>'index',$id));
              } 
       }
           if(empty($this->request->data)){               
           $this->request->data = $this->Book->read(NULL,$id);
        }           
   }

并查看ctp文件

<?php  echo $this->Form->create('Book');?>
<fieldset>
    <legend> Edit New Book </legend>
    <?php

    echo $this->Form->input('isbn');
    echo $this->Form->input('title');
    echo $this->Form->hidden('id'); 
    echo $this->Form->input('description');
    echo $this->Form->input('author_name');
    ?>
</fieldset>
<?php echo $this->Form->end('Edit Book');?>

1 个答案:

答案 0 :(得分:1)

检查数据库配置

字符串dummy@应该是要连接的数据库的名称。

检查database.php文件是否配置为连接到有效数据库(如果有疑问,请参阅default database.php file),它应如下所示:

class DATABASE_CONFIG {

public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'user',
    'password' => 'password',
    'database' => 'database_name', // <- "dummy@" ?
    'prefix' => '',
    //'encoding' => 'utf8',
);