0

Please excuse the code I've posted that isn't code formatted. couldn't get the four spaces to work sometimes.

Hi. Looking for some insight on this error caused by num_rows() function in CodeIgniter.

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

It seems to be somehow rooted in this...possibly:

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

Line 427 reads: $v = ' '.$this->escape($v);

and is from the function: protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)

I'm using CodeIgniter and IonAuth and the problem seems to be coming from num_rows() when I call this function: public function login($identity, $password, $remember=FALSE) { $this->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;
}

I'm wondering if it could be a problem with the query they're using there. Any leads on CI_DB_mysql_driver would be helpful...

Thanks in advance!

Patrick
  • 241
  • 2
  • 8
  • 18
  • It turns out this problem was cause by some functions that I added to the Ion_auth_model. Restoring that file and separating the functions to a different model fixed this problem. Thanks anyways. – Patrick Apr 15 '13 at 23:02

2 Answers2

0

Change your query code to this:

 $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');

The error was because you did not execute the query but you just generated the SQL code for it.

Vassilis Barzokas
  • 3,105
  • 2
  • 26
  • 41
0

You've changed something for testing - this is not from the actual source:

    $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;

pull/download again from github

jmadsen
  • 3,635
  • 2
  • 33
  • 49