活动记录代码点火器转换问题


active record codeigniter conversion issue

我正在尝试将下面的查询转换为codeigniter,但我这边似乎没有运气

     public function activation ($email, $token) 
    {
       $search =  $this->db->query("SELECT email, token, active FROM gamers WHERE email='".$email."' AND token='".$token."' AND active='0'"); 
       $match  = mysql_num_rows($search);
       if($match > 0){
           // We have a match, activate the account
           mysql_query("UPDATE gamers SET active='1' WHERE email='".$email."' AND token='".$token."' AND active='0'") or die(mysql_error());
           redirect('index.php/email_verification/account_activated');
       }else{
            // No match -> invalid url or account has already been activated.
            redirect('index.php/email_verification/activation_error');
          }
       }
     }

我试过这个

public function activation ($email, $token)  {

          $search =  $this->db->query("SELECT email, token, active FROM gamers WHERE email='".$email."' AND token='".$token."' AND active='0'"); 
          $match  = mysql_num_rows($search);
          $query = $this->db->get();
          $match = $query->num_rows();

         if($match > 0){
        // We have a match, activate the account
            mysql_query("UPDATE gamers SET active='1' WHERE email='".$email."' AND token='".$token."' AND active='0'") or die(mysql_error());
            redirect('index.php/email_verification/account_activated');
        }else{
            // No match -> invalid url or account has already been activated.
             redirect('index.php/email_verification/activation_error');
              }
          }
    }

但行不通。

使用活动记录:

$this->db->select('mail, token, active');
$this->db->where('email',$email);
$this->db->where('token',$token);
$this->db->where('active', 0);
$query = $this->db->get('gamers'); //table name here 
if($query->num_rows() > 0){
   //do something
   //to update
   $this->db->set('active',1); //You must set in order to update
   $this->db->where('email', $email);
   $this->db->where('token',$token);
   $this->db->where('active', 0);
   if($this->db->update('gamers'){
       redirect('index.php/email_verification/account_activated');
    }else{
       //handle it son
    }
}