【问题标题】:Error: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'dummy@.books.id' in 'where clause'错误:SQLSTATE [42S22]:找不到列:1054 'where 子句'中的未知列'dummy@.books.id'
【发布时间】:2013-08-22 10:43:20
【问题描述】:

我在查找此错误的来源时遇到了一些麻烦:

错误: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');?>

【问题讨论】:

  • 请显示您的图书型号代码 - 其余部分不相关
  • 在模型文件中没有写入任何内容

标签: cakephp cakephp-2.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',
);

【讨论】:

  • 在配置文件中,数据库名称是正确的..但是找不到错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-03-29
  • 2023-04-07
  • 2019-08-18
  • 2021-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多