Welcome Guest, Not a member yet? Register   Sign In
Query returns no result?
#1

[eluser]grolle[/eluser]
Hi,

I'm using this in a function of an own lib to identify an user, but I get no result:
Code:
$sql = "SELECT * FROM ci_users WHERE username = '".$username."' AND active = 1 LIMIT 1";
$query = $this->CI->db->query($sql);
Code:
print_r($query->result());
returns an empty array.
Code:
print_r($query);
shows that there are zero num_rows.
If I do
Code:
print_r($this->CI->db->last_query());
and execute the query via phpMyAdmin everthing works fine and I get one row.

Whats wrong with this code?

Best regards...
#2

[eluser]darkhouse[/eluser]
Is it using the right database? Sometimes during development we use a local database and a remote database, and sometimes the data differs (this actually just happened last week, one of my developers wasn't getting a result... because she didn't have any data in that table in her local database).

I have no other suggestion if the query from last_query() is working in phpMyAdmin.
#3

[eluser]grolle[/eluser]
Hi,

I think there is somewhere a problem with utf8. If I run only
Code:
SELECT * FROM ci_users
it works correct. Before executing the statement I use
Code:
$username = $this->CI->db->escape_str($username);
. The username is something with "รถ"-character. But I don't know where to search. It is displayed correct everywhere.

Best regards ..

// Edit: Found it. There was
Code:
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
missing in the view




Theme © iAndrew 2016 - Forum software by © MyBB