Also some database fields can be renamed to better:
roles.id -> roles.role_id
roles.name -> roles.role_name
users.id -> users.user_id
When I wan’t to use your library in big project where table ‘users’ have relations with other tables, ‘users.id’ will be a pain. So just look at all your primary keys for improvement.
Also you can benefit from it in places like this:
SELECT $u_table.*,
$r_table.name AS role_name
->
SELECT $u_table.*,
$r_table.role_name
About AR and UPPER in your models.
$sql = "SELECT 1 FROM ".$this->_table." WHERE UPPER('username') = UPPER(?)";
return $this->db->query($sql, array($username));
->
$this->db->select('username');
$this->db->where('LOWER(username)=',strtolower($username));
return $this->db->get($this->_table);
I use lower here, but you can use upper if you like it more. It works for me on PostgreSQL, I think should work on MySQL and other databases too.