Welcome Guest, Not a member yet? Register   Sign In
Getting error when calling affected_rows()
#1

[eluser]kyleect[/eluser]
EDIT:

The query is run and the data is inserted even with the error. I get the same error when I try to run num_rows()

--

I'm trying to call affected_rows() in my model and I'm getting an error when I do. See below for the code and error. Note: both $this->data and $this->query are properties of the model

Code:
public function register($data)
        {
            $this->data['email'] = $data['email_address'];
            $this->data['username'] = $data['username'];
            $this->data['password'] = md5($data['password']);
            
            
            $this->query = $this->db->query("
            INSERT INTO `users`
            (`email`, `username`, `password`)
            VALUES
            ('{$this->data['email']}', '{$this->data['username']}', '{$this->data['password']}')
            ");
            
            if($this->query->affected_rows() > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

Quote:Fatal error: Call to a member function affected_rows() on a non-object in /application/models/Users.php on line 45
#2

[eluser]imn.codeartist[/eluser]
Try using following code

Code:
if($this->db->affected_rows() > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
#3

[eluser]kyleect[/eluser]
I'll try that when I get home but I have never had issues using this approach. Infact, I added those properties to MY_Model and use them for all my queries.
#4

[eluser]InsiteFX[/eluser]
dixcoder is correct!

Code:
$this->db->affected_rows()

Is the correct way to call the method.

Enjoy
InsiteFX
#5

[eluser]Unknown[/eluser]
Connect the costumer care
#6

[eluser]kyleect[/eluser]
Ok so I've finally had some time to work on this. It seems that with SELECT queries, I have to assign the query to a variable to use result_array however I when I do an INSERT query, I have to use $this-db. Is this correct? It feels like I didn't have to do this before. I just recently upgraded to the newest stable version of CI if that helps.




Theme © iAndrew 2016 - Forum software by © MyBB