2013-05-05 67 views
2

我工作的这一点,使用CRUD教程:笨没有数据库选择

public function get($id = NULL, $single = FALSE){ 

    if ($id != NULL) { 
     $filter = $this->_primary_filter; 
     $id = $filter($id); 
     $this->db->where($this->_primary_key, $id); 
     $method = 'row'; 
    } 
    elseif($single == TRUE) { 
     $method = 'row'; 
    } 
    else { 
     $method = 'result'; 
    } 

    if (!count($this->db->ar_orderby)) { 
     $this->db->order_by($this->_order_by); 
    } 
    return $this->db->get($this->_table_name)->$method(); 
} 

但我得到这个错误信息:

A Database Error Occurred 

Error Number: 1046 

No database selected 

SELECT * FROM (`pages`) WHERE `slug` = 'about' ORDER BY `order` 

Filename: /var/application/core/MY_Model.php 

Line Number: 34($this->db->get($this->_table_name)->$method();) 

如何选择数据库?

+0

似乎没有找到数据库“网页”。检查在application/config/database上是否正确定义了正确的名称和配置设置。 – 2013-05-05 23:50:22

+0

@Lior其实'页面'是表格... – Hailwood 2013-05-05 23:54:59

+0

是页面是表格名称我怎样才能{SELECT * FROM('pages')where'slug' ='about'ORDER BY'order'}这些查询起作用,谢谢 – mercy 2013-05-06 00:06:10

回答

0

,你需要,如果你正在使用的环境可能需要编辑/application/config/{ENVIRONMENT}/database.php文件中/application/config/database.php

填写你的数据库的细节也。

+0

$ active_group ='default'; $ active_record = TRUE; $ db ['default'] ['hostname'] ='localhost'; $ db ['default'] ['username'] ='root'; $ db ['default'] ['password'] ='密码'; $ db ['default'] ['database'] ='databasename'; – mercy 2013-05-05 23:59:33

+0

即时通讯使用环境,我设置它正确(我认为),但这些crud不工作 – mercy 2013-05-06 00:00:46

+0

尝试'死('

'.print_r($this->db, true).'
');'某处,检查什么值在'用户名','密码','主机名' abd'数据库'键。 – Hailwood 2013-05-06 00:09:13