|
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.
|
|