Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Losing variable values when passed to library
#1

[eluser]Armchair Samurai[/eluser]
Here's the situation: when I pass variable to a library, for some reason CI seems to 'lose track' of them when passed through CI's $this->db->escape() function. I've never seen this behavior before from CI, so I'm stumped. I created a simple test using echos:

Code:
function login($user, $pw)
{
    $ci =& get_instance();

    echo "$user:$pw<br>";
    
    $ci->db->select('password');
    $ci->db->where('name', $user);
    $query = $ci->db->get('kp_users', 1);

    echo $ci->db->last_query().'<br>';
        
    $sql = "SELECT password
            FROM kp_users
            WHERE name = ?
            LIMIT 1";
    $query = $ci->db->query($sql, array($user));

    echo $ci->db->last_query().'<br>';

    $temp = $ci->db->escape($user);
    $sql = "SELECT password
            FROM kp_users
            WHERE name = $temp
            LIMIT 1";
    $query = $ci->db->query($sql);

    echo $ci->db->last_query().'<br>';
        
    $sql = "SELECT password
            FROM kp_users
            WHERE name = '$user'
            LIMIT 1";
    $query = $ci->db->query($sql);

    echo $ci->db->last_query();
    echo "<br>$user:$pw";
    exit;
}

produces this:
Code:
foo:bar
SELECT password FROM kp_users WHERE name = '' LIMIT 1
SELECT password FROM kp_users WHERE name = '' LIMIT 1
SELECT password FROM kp_users WHERE name = '' LIMIT 1
SELECT password FROM kp_users WHERE name = 'foo' LIMIT 1
foo:bar

I echoed the variables initially to makes sure the function was receiving them, and that was okay. If the data is not escaped through CI, it's fine, but otherwise produces empty strings. Both variables are simple alpha numeric strings.

Any ideas? I'm getting close to the point where I'm going to scrap this library (it was one the first things I coded in CI well over a year ago and hence, looking back, somewhat cringe worthy) and integrate an alternate version, but that would be a lot of work.


Messages In This Thread
[SOLVED] Losing variable values when passed to library - by El Forum - 12-10-2007, 11:56 PM
[SOLVED] Losing variable values when passed to library - by El Forum - 12-11-2007, 12:11 AM
[SOLVED] Losing variable values when passed to library - by El Forum - 12-11-2007, 04:15 AM
[SOLVED] Losing variable values when passed to library - by El Forum - 12-11-2007, 09:08 PM
[SOLVED] Losing variable values when passed to library - by El Forum - 12-11-2007, 10:12 PM
[SOLVED] Losing variable values when passed to library - by El Forum - 12-16-2007, 09:05 PM



Theme © iAndrew 2016 - Forum software by © MyBB