Welcome Guest, Not a member yet? Register   Sign In
Problem retrieving rows
#1

[eluser]Unknown[/eluser]
I am writing a simple site to get familiar with Code Igniter. I am at the first step of getting a simple user login going. When I try to retrieve data from the database, I get a Windows dialog saying "Apache HTTP Server has encountered a problem and needs to close. We are sorry for the inconvenience." Here is what I have so far:

My User model:
Code:
<?php

class User extends Model {
    var $id = "";
    var $email = "";
    #TODO move password to its own table.
    var $password = "";
    
    function User() {
        parent::Model();
        $this->load->database();
    }
    
    function create_user($id, $email, $password) {
        $this->id = $id;
        $this->email = $email;
        $this->password = $password;
        
        $data = array("id" => $id, "email" => $email, "password" => $password);
        
        $this->db->insert("user", $data);
    }
    
    function validate_user($email, $password) {
        $this->db->where("email", $email);
        $this->db->where("password", $password);
        logmsg("USER1");
        $query = $this->db->get("user");
        logmsg("SQL = ".$this->db->last_query());
        logmsg("query = ".print_r($query, true));
        if ($query->num_rows() > 0) {
            $user = new User();
        logmsg("USER2");
            $row = $query->first_row("array");
        logmsg("USER3");
            $user->id = $row["id"];
            $user->email = $row["email"];
        logmsg("USER4");
            return $user;
        }
        else {
            return false;
        }
    }
}
?>

The freeze occurs at $row = $query->first_row("array");. I have tried $query->result(), $query->result_array() and $query->first_row() (without array). The same thing happens on all of them. I logged the SQL and the statement generated is correct and when I use it directly in the database it works properly. Here is the SQL:
Code:
SQL = SELECT * FROM (`user`) WHERE `email` = '[email protected]' AND `password` = 'test'
Here is the result of that SQL in the MySQL command line:
Code:
+------+---------------+----------+
| id   | email         | password |
+------+---------------+----------+
| test | [email protected] | test     |
+------+---------------+----------+

When I do a print_r() on the $query object it shows that 1 row is supposed to be there, but there is no data:
Code:
query = CI_DB_mysqli_result Object
(
    [conn_id] => mysqli Object
        (
        )

    [result_id] => mysqli_result Object
        (
        )

    [result_array] => Array
        (
        )

    [result_object] => Array
        (
        )

    [current_row] => 0
    [num_rows] => 1
    [row_data] =>
)

And one more thing. Here is what I see in the event viewer:
Code:
Faulting application httpd.exe, version 2.2.9.0, faulting module php_mysqli.dll, version 5.2.6.6, fault address 0x00002beb.

If anyone has eny ideas, I would appreciate it.

Thanks.
#2

[eluser]Mat-Moo[/eluser]
Code:
$user = new User();
Why are you creating a new user model? Shouldn't it be
Code:
if ($query->num_rows() > 0) {
        $row = $query->first_row("array");
        logmsg("USER3");
        $this->id = $row["id"];
        $this->email = $row["email"];
        logmsg("USER4");
        return $user;
        }
        else {
            return false;
        }
#3

[eluser]Unknown[/eluser]
Thanks for your reply.

I had it your way first and changed it as something to try and fix the problem. Now on one computer I am using it works fine, but it still doesn't work on the other one. It's a very strange problem. I even tried rebooting the machine and it still didn't work. When I write the access code myself it works fine. So it is either a bug in Code Igniter or a problem in the way I am using it.
#4

[eluser]Mat-Moo[/eluser]
I think if this was a CI bug there would be lot of people with issues as your doing pretty basic stuff. Have both systems got the latest version of CI? Are you running any .htaccess files?




Theme © iAndrew 2016 - Forum software by © MyBB