我正在使用数据库开发codeigniter项目,它在本地主机上运行良好,但是当我将它上传到真实服务器上时,发生了很多问题。
我真的做了很多搜索,但我找不到解决方案。
当我从数据库中检索数据并给我这个错误时,result_array() 函数不起作用" Fatal error: Call to a member function result() on a non-object in /home/mostafa/public_html/Sales/application/models/m_login.php on line 13 "
这是我的控制器代码
class c_login extends CI_Controller {
public function index() {
$this->load->view('login');
}
public function signin(){
$username = $this->input->post('username');
$password = $this->input->post('password');
$this->load->model('m_login');
$user = $this->m_login->signin($username, $password);
if(!$user){
echo "<script>alert('Your Username Or Password is Incorrect');</script>";
}else{
//set session
$userData = array(
'id' => $user[0]['id'],
'name' => $user[0]['name'],
'admin' => $user[0]['admin']
);
$this->session->set_userdata($userData);
if ($user[0]['admin'] == 1) {
redirect('c_home_admin');
}else{
redirect('c_home_user');
}
}
}
}
这是模型代码
class m_login extends CI_Model{
function insertUser($data) {
$this->db->insert('users', $data);
}
public function signin($username, $password){
$this->db->select('*')->from('users')->where(array('username' => $username, 'password' => $password));
$query = $this->db->get();
return $query->result_array();
}}
这是 database.php 配置:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '**********';
$db['default']['database'] = 'mydb';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
提前致谢