0

I got the following snippet to get some userrights out of the db:

    $tmp   = "SELECT REPLACE(group_concat(CAST(".$role." AS CHAR)),',','') AS rights FROM functionrights ORDER BY id ASC";
    $query = $this->CI->db->query($tmp);
    if($query->num_rows()>0){
        $row = $query->row(); 
        return $row->rights;

This returns nothing. If I execute the statement direct everything is ok?! What is wrong here?

4
  • try to use: return $query->result();and then you can manipulate the result Commented Jan 22, 2013 at 14:38
  • This returns: Array ( [0] => stdClass Object ( [rights] => ) ) Commented Jan 22, 2013 at 14:43
  • Examine your raw SQL. Try: print $this->CI->db->last_query; perhaps you have an error in your SQL Commented Jan 22, 2013 at 15:00
  • As I mentioned above - if I execute the raw statement via Navicat or Netbeans (SELECT REPLACE(group_concat(CAST(role1 AS CHAR)),',','') AS rights FROM functionrights ORDER BY id ASC) everthing is ok. Commented Jan 22, 2013 at 15:16

1 Answer 1

1

Change $this->CI->db->query to $this->db->query

The ->CI is not necessary. Also, you have no } tag (but that could be just a copy/paste thing).

Besides that: ->row() returns one result, while ->result() returns all results.

Sign up to request clarification or add additional context in comments.

2 Comments

Hey, it's a snippet ;-). I use $this->CI because it is a library.
Please delete this - wrong database where the table values are empty - damn!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.