[eluser]spaquet[/eluser]
I read many posts on this forum but for now it does not seem to be working at all...
My application uses an ERP as backend and offer to some users a easy way to get data from it and track some of their activity on the side of this ERP, reason why there is a second database (to manange CI_Session, user activity and some requests that are not part of the ERP).
What I've done:
I added a second database in database.php (sugarcrm) and have the following code for my user controller :
Code:
Class User_model extends CI_Model {
private $db_erp;
function __construct() {
// Call the Model constructor
parent::__construct();
$this->db_erp = $this->load->database('sugarcrm', TRUE);
}
public function validates_user_from_erp($matricule, $password) {
$sql = "SELECT * FROM users JOIN users_cstm ON users.id=users_cstm.id_c ";
$sql += "WHERE users_cstm.matricule_c=" + $matricule + " AND ";
$sql += "users_cstm.password_c=md5('" + $password + "');";
$query = $this->db_erp->query($sql);
if ($query->num_rows == 1) {
return true;
}
return false;
}
I made sure the database user connect to the database and that the query is valid (I tested in on the database).
Now when calling alidates_user_from_erp from my login controller
Code:
public function validate_credentials() {
$this->output->enable_profiler(TRUE);
$this->form_validation->set_rules('username', 'Utilisateur', 'required');
$this->form_validation->set_rules('password', 'Mot de passe', 'required');
if ($this->form_validation->run() == FALSE) {
$this->index();
} else {
$this->load->model('User_model');
//Check if user is active and if his/her credentials are valid
$username = $this->input->post('username'); // aka matricule
$password = $this->input->post('password');
if( $this->User_model->validates_user_from_erp($username, $password) ) {
redirect('dashboard');
} else {
$this->index();
}
}
}
I have the following error message :
Quote:Trying to get property of non-object
refering to the line
Quote:$query->num_rows == 1
of my User model.
It looks like the $query object is not a database object as expected and thus I can not use database methods on it.
Any help is welcome as I have the feeling I've done what I read in CI User Guide and several posts from this forum.