我正在尝试将下面的查询翻译成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');
}
}
}
但不会工作。
答案 0 :(得分:1)
使用有效记录:
$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
}
}