用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2161|回复: 2
收起左侧

[讨论/交流] 数据库连接问题

[复制链接]
发表于 2011-5-27 10:16:49 | 显示全部楼层 |阅读模式
application/config/database.php 中数据库配置是$db['default']['hostname'] = "localhost";之类 和手册完全一样 然后做了一个模型和控制器 但是怎么都搞不出来。
class Mypapemodel extends CI_Model{
function _construct(){
  parent ::_construct();
  
}
function test(){
  $this->load->database($db);
  $query=$this->db->query('select name from user where username=0304070519');
  foreach($query->result()as$row){
  echo $row->name;  
  }
  $this->db->close();
}
}

class Mydb extends CI_Controller{
function _construct(){
  parent ::_construct();
}
function index(){
  //$this->load->database($config);
  $this->load->model('Mypapemodel');
  $this->Mypapemodel->test();
}
}
错误显示:
A PHP Error was encounteredSeverity: Notice
Message: Undefined variable: db
Filename: models/mypapemodel.php
Line Number: 8

An Error Was EncounteredYou have not selected a database type to connect to.

发表于 2011-5-27 10:20:59 | 显示全部楼层
$this->load->database($db);红色的是神马!!!
 楼主| 发表于 2011-5-27 10:30:32 | 显示全部楼层
这个 那个。。。解决了。。

本版积分规则