Welcome Guest, Not a member yet? Register   Sign In
num_rows not work on object
#1

[eluser]RJ[/eluser]
Hello,

I've been having a bear of a time getting a result back from our db. Finally removed the num_rows check and did a print_r on $row to find this result:
Quote:stdClass Object ( [DEVICETYPE] => 1 [TO_CHAR(SUBVERSION)] => 0 )

Off of this query
Code:
foreach ($query->result() as $row)
                {
                  log_message('debug',print_r($row));
                  return true;
                }

But the darn thing fails when I put in the num rows check:
Code:
if ($query->num_rows() > 0)
        {
            foreach ($query->result() as $row)
                {
                  log_message('debug',print_r($row));
                  return true;
                }
        }

Any idea why?
#2

[eluser]jedd[/eluser]
Well, what is $query->num_rows()?
#3

[eluser]RJ[/eluser]
Code:
$query = $TT->query("SELECT devicetype, TO_CHAR(subversion) FROM ttdevice WHERE msisdn = '".$this->MSISDN."' AND unitid = '".$this->UNITID."'");

This is the query; if you leave out the num_rows check and dump $rows you get:
Quote:stdClass Object ( [DEVICETYPE] => 1 [TO_CHAR(SUBVERSION)] => 0 )

NUM_ROWS produces a result of -1. So based on the foreach in the beginning of this post, I can not have a check on $query. I think num_rows doesn't work because its not a row, i'm getting back objects; but the user guide said the num_rows check should work... and doesn't.

Does that makes sense?
#4

[eluser]jedd[/eluser]
And the profiler reports the passed SQL query as being .. ?

And if you type that SQL query verbatim at a MySQL's prompt, what do you get back?
#5

[eluser]Dam1an[/eluser]
What do you get if you call size_of() on the query
It may be possible that you're getting an array of results instead of an object
#6

[eluser]RJ[/eluser]
This is an ODBC query, the value of $query is:
Quote:CI_DB_odbc_result Object ( [conn_id] => Resource id #123 [result_id] => Resource id #124 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => -1 [row_data] => )

The query being ran is:
Code:
SELECT devicetype, subversion
FROM (ttdevice)
WHERE msisdn = ‘xxxx'
AND unitid = ‘xxxx’

I can get the data out now running the foreach without num_row check; num_row doesn't recognize the result above as a row thereby returning value of -1. There has to be a different check or maybe pull the data out as an array and check?




Theme © iAndrew 2016 - Forum software by © MyBB