[英]codeigniter result_array is not working on real server
I'm working on codeigniter project with a database and it's working perfectly on the local host but when i uploaded it on real server alot of problems occurred. 我正在使用数据库进行codeigniter项目,并且在本地主机上运行良好,但是当我将其上载到真实服务器时,出现了很多问题。
I really made a lot of search but i couldn't find solution. 我确实进行了大量搜索,但找不到解决方案。
result_array() function is not working when i retrieve data from database and give me this error " 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 "
当我从数据库中检索数据并给我这个错误时,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 "
this is my controller code 这是我的控制器代码
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');
}
}
}
} }
and this is the model code 这是模型代码
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();
}}
and this is the database.php configurations : 这是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;
Thanks in advance 提前致谢
The first thing I would check is whether your database schema is exactly the same on development as it is on live. 我要检查的第一件事是您的数据库架构在开发中与在运行中是否完全相同。 If the tables are not the same (eg missing a field) you will get that error.
如果表不相同(例如,缺少字段),则会收到该错误。
EDIT 编辑
Try rewrite your SQL query as follows: 尝试如下重写SQL查询:
$sql = "
SELECT * FROM `users` where `username` = ? AND `password` = ?
";
$q = $this->db->query($sql, array($username, $password));
return $q->result_array();
(Sorry - posted it here in my answer, as the comment is looking wonky...) (对不起-由于评论看起来很古怪,所以将其张贴在我的答案中)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.