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.


Messages In This Thread
Problem retrieving rows - by El Forum - 11-30-2009, 09:03 PM
Problem retrieving rows - by El Forum - 12-01-2009, 03:22 AM
Problem retrieving rows - by El Forum - 12-02-2009, 08:59 AM
Problem retrieving rows - by El Forum - 12-02-2009, 09:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB