What is correct way to query SELECT WHERE on CodeIgniter
Since two days, I've been trying to solve validation which compare username from input 
and username in database. It always gives me correct results but it shows <br/> 
A PHP Error was encountered
Severity: Warning
Message: preg_match() expects parameter 2 to be string, object given
Filename: mysql/mysql_driver.php
Line Number: 198
AND<br/>
A PHP Error was encountered
Severity: Warning
Message: preg_match() expects parameter 2 to be string, object given
Filename: database/DB_driver.php
Line Number: 622

Here is the code I've done so far<br/>
controller
        
    class Welcome extends CI_Controller {
       public function __construct() {
          parent::__construct();
          $this->load->model('Welcome_model');
       }
       
       public function index(){
          $this->form_validation->set_rules('username', 'Username', 'required|callback_username_check');
          $this->form_validation->set_rules('password', 'Password', 'required');
          $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
          $this->form_validation->set_rules('email', 'Email', 'required');
    
          if($this->form_validation->run() == FALSE){
             $this->load->view('welcome_message');
          }else{
             $this->load->view('formsuccess');
          }
        }
       
       public function username_check($username){
          if($this->Welcome_model->check_by_username($username)){
             $this->form_validation->set_message('username_check', 'This %s has been taken');
             return FALSE;
          }else{
             return TRUE;
          }
       }
     }
    
    class Welcome_model extends CI_Model{
       public function check_by_username($username){
          $q = $this->db->get_where('infos', array('username'=>$username));
          $r = $this->db->query($q);
          if($r->num_rows()>0)   
             return FALSE;
          else
             return TRUE;
       }
    }

Here I am trying to retrieve username from database and compare with the one comes from form input.
I believe the errors come from $r = $this->db->query($q); because I am calling the query on the query, but I've been googling for days and I don't know how to solve it to correct way. Could you please some experts of you pointing me what I did do wrong?

T.I.A
 
What is correct way to query SELECT WHERE on CodeIgniter
===

Since two days, I've been trying to solve validation which compare username from input 
and username in database. It always gives me correct results but it shows <br/> 
A PHP Error was encountered
Severity: Warning
Message: preg_match() expects parameter 2 to be string, object given
Filename: mysql/mysql_driver.php
Line Number: 198
AND<br/>
A PHP Error was encountered
Severity: Warning
Message: preg_match() expects parameter 2 to be string, object given
Filename: database/DB_driver.php
Line Number: 622

Here is the code I've done so far<br/>
controller
        
    class Welcome extends CI_Controller {
       public function __construct() {
          parent::__construct();
          $this->load->model('Welcome_model');
       }
       
       public function index(){
          $this->form_validation->set_rules('username', 'Username', 'required|callback_username_check');
          $this->form_validation->set_rules('password', 'Password', 'required');
          $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
          $this->form_validation->set_rules('email', 'Email', 'required');
    
          if($this->form_validation->run() == FALSE){
             $this->load->view('welcome_message');
          }else{
             $this->load->view('formsuccess');
          }
        }
       
       public function username_check($username){
          if($this->Welcome_model->check_by_username($username)){
             $this->form_validation->set_message('username_check', 'This %s has been taken');
             return FALSE;
          }else{
             return TRUE;
          }
       }
     }
    
    class Welcome_model extends CI_Model{
       public function check_by_username($username){
          $q = $this->db->get_where('infos', array('username'=>$username));
          $r = $this->db->query($q);
          if($r->num_rows()>0)   
             return FALSE;
          else
             return TRUE;
       }
    }

Here I am trying to retrieve username from database and compare with the one comes from form input.
I believe the errors come from $r = $this->db->query($q); because I am calling the query on the query, but I've been googling for days and I don't know how to solve it to correct way. Could you please some experts of you pointing me what I did do wrong?

T.I.A
 