Welcome Guest, Not a member yet? Register   Sign In
num_rows not working in ODBC Multiple DB object
#1

I use ODBC DB
I found that I cannot use num_rows when it is a database object
For example:
$this->load->database('testing');
$sql = "SELECT top 10 * from [haha].[dbo].[Info]";

$query = $this->db->query($sql);
echo "1.";
echo $query->num_rows();
echo "<hr/>";


$main_db = $this->load->database('testing',true);
$query = $main_db->query($sql);
echo "2.";
echo $query->num_rows();
echo "<hr/>";

And the result would be:
1.10

2.0



Is it a CI bug or someone can give me some advice to fix it?
Reply
#2

One more problem
I found that if I just use $query->result(), I can get the result normally with both connection

but once I use $query->num_rows() in object $main_db
the $query will turn All Null

for example,
$query = $main_db->query($sql);
foreach ($query->result() as $row)
{
echo $row->a.",";
}
echo "<br/>";

$query = $main_db->query($sql);
echo $query->num_rows();
foreach ($query->result() as $row)
{
echo $row->a.",";
}


and result would be:
a,b,c,d,e,f,g,h,i,j,
0
^(this line supposed to run foreach too but nothing)
Reply
#3

While it's possible that's a bug in the ODBC driver, the current best practice is to NOT use num_rows. As you said, you can get the answer just by calling result(), row() or any of their siblings. The result* methods will always return an empty array IIRC, if there's no results, while the row* methods will always return null.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB