由IonAuth和$ query-> num_rows()引起的CodeIgniter系统问题

时间:2013-04-12 08:40:27

标签: mysql codeigniter ion-auth

请原谅我发布的格式不是code的代码。无法让这四个空间有时工作。

您好。寻找有关CodeIgniter中num_rows()函数导致的此错误的一些见解。

Fatal error: Call to undefined method CI_DB_mysql_driver::num_rows() in [my controller]    

似乎在某种程度上根植于此......可能:

A PHP Error was encountered
Severity: 4096

Message: Object of class CI_DB_mysql_driver could not be converted to string

Filename: database/DB_active_rec.php

Line Number: 427

第427行写道:     $ v =''。$ this-> escape($ v);

并且来自函数:     protected function _where($ key,$ value = NULL,$ type ='AND',$ escape = NULL)

我正在使用CodeIgniter和IonAuth,当我调用此函数时,问题似乎来自num_rows():     公共功能登录($ identity,$ password,$ remember = FALSE)     {         $这 - > trigger_events( 'pre_login');

    if (empty($identity) || empty($password))
    {
        $this->set_error('login_unsuccessful');
        return FALSE;
    }

    $this->trigger_events('extra_where');

    $query = $this->db->select($this->identity_column . ', username, email, id, password, active, last_login')
                      ->where($this->identity_column, $this->db->escape_str($identity))
                      ->limit(1);

    echo $query;

    if ($query->num_rows() === 1)
    {
        $user = $query->row();

        $password = $this->hash_password_db($user->id, $password);

        if ($password === TRUE)
        {
            if ($user->active == 0)
            {
                $this->trigger_events('post_login_unsuccessful');
                $this->set_error('login_unsuccessful_not_active');

                return FALSE;
            }

            $session_data = array(
                'identity'             => $user->{$this->identity_column},
                'username'             => $user->username,
                'email'                => $user->email,
                'user_id'              => $user->id, //everyone likes to overwrite id so we'll use user_id
                'old_last_login'       => $user->last_login
            );

            $this->update_last_login($user->id);

            $this->clear_login_attempts($identity);

            $this->session->set_userdata($session_data);

            if ($remember && $this->config->item('remember_users', 'ion_auth'))
            {
                $this->remember_user($user->id);
            }

            $this->trigger_events(array('post_login', 'post_login_successful'));
            $this->set_message('login_successful');

            return TRUE;
        }
    }

    //Hash something anyway, just to take up time
    $this->hash_password($password);

    $this->increase_login_attempts($identity);

    $this->trigger_events('post_login_unsuccessful');
    $this->set_error('login_unsuccessful');

    return FALSE;
}

我想知道它们在那里使用的查询是否存在问题。 CI_DB_mysql_driver上的任何线索都会有帮助......

提前致谢!

2 个答案:

答案 0 :(得分:0)

将您的查询代码更改为:

 $this->db->select($this->identity_column . ', username, email, id, password, active, last_login')
                  ->where($this->identity_column, $this->db->escape_str($identity))
                  ->limit(1);
 $query = $this->db->get('YOUR_TABLE_NAME');

错误是因为您没有执行查询,而是刚刚为它生成了SQL代码。

答案 1 :(得分:0)

你已经改变了一些东西进行测试 - 这不是来自实际来源:

    $query = $this->db->select($this->identity_column . ', username, email, id, password, active, last_login')
                  ->where($this->identity_column, $this->db->escape_str($identity))
                  ->limit(1);

echo $query;

从github再次拉/下载