Jump to content

odbc_result_all returns incremented number each time called?


OceanMachine

Recommended Posts

I have a strange problem that I do not understand.  I was checking something with odbc_result_all() and I am seeing some strange behaviour.

 

When I first call odbc_result_all(), the rows returned are fine, and the return value is the number of rows (in this case 1), as expected.  I then use odbc_fetch_row($rid, 0) to reset the cursor.  Now, when I call odbc_result_all() again, the returned row is correct, but the return value from the function is now 2 (as opposed to 1, as only 1 row is returned).  If I do the same thing (reset cursor and call again), then the function returns with 3!  Am I missing something here?

 

<?php
$td1_conn = odbc_connect("host","username","pass");
$order_ref = "XYZ123";

$qry_dist="
select distinct st_order_id
from mi_order
where st_cust_order_ref like '$order_ref%'";

$rid1 = odbc_exec($td1_conn, $qry_dist);

echo odbc_result_all($rid1);
odbc_fetch_row($rid1, 0);

echo odbc_result_all($rid1);
odbc_fetch_row($rid1, 0);

echo odbc_result_all($rid1);

?>

 

The above code gives me the following output:

 

ST_ORDER_ID

123456789-001

1

ST_ORDER_ID

123456789-001

2

ST_ORDER_ID

123456789-001

3

 

 

I can't work it out... can anyone tell me why this might be please?

 

Thanks in advance.

Link to comment
Share on other sites

On further testing, it seems that when odbc_result_all() returns 2 rows of data, the output is increased by 2 each time the function is called:

 

ST_ORDER_ID

123456789-001

234567890-001

2

ST_ORDER_ID

123456789-001

234567890-001

4

ST_ORDER_ID

123456789-001

234567890-001

6

 

Does anyone have any ideas please?

Link to comment
Share on other sites

That's clearly not all your code that is producing the posted output.

 

Sorry, what makes you think that isn't all my code?

 

That is the code I am using, verbatim, except I have changed the username and password in the connection string, and the order ref.  Apart from that, this is the code and the ouput EXACTLY as I have it, and a copy and paste of the exact output that I am getting shown on the web page...

 

ST_ORDER_ID

123456789-001 <---- these 2 lines (column title and row) are the output from the 1st call of odbc_result_all()

 

1 <---- this is the output of the 1st echo of the function (which is echoing the return value of the 1st function call)

 

ST_ORDER_ID

123456789-001 <---- these 2 lines (column title and row) are the output from the 2nd call of odbc_result_all()

 

2 <---- this is the output of the 2nd echo of the function (which is echoing the return value of the 2nd function call)

 

ST_ORDER_ID

123456789-001 <---- these 2 lines (column title and row) are the output from the 3rd call of odbc_result_all()

 

3 <---- this is the output of the 3rd echo of the function (which is echoing the return value of the 3rd function call)

Link to comment
Share on other sites

Anyone know why this is happening please?

 

Additional info: I am using Oracle 10g as the database in this case.  odbc_num_rows() does not work for me (always returns -1), but it seems this is common for certain drivers that don't know how to respond to odbc_num_rows().

 

I am not doing anything other than the code in my first post, and the output in my first post is exactly what comes back from the code.

 

Is there some internal counter that I don't know about, other than the one that supposedly gets reset when I use odbc_fetch_row($rid1, 0)?

 

I realise there is a workaround by looping through each row using a counter and odbc_fetch_row, but it seems the code I posted should give the same return value each time, but it does not...

Link to comment
Share on other sites

Probably. Is there some reason you are using odbc_result_all() more than once on the same result set?

 

Well, I was trying to use it to count the number of rows (in the absence of odbc_num_rows() not working), and then calling it again to display the output for debugging purposes.  I noticed this strange behaviour and could not understand what was wrong.  I thought using it to count the number of rows would be 'cleaner' than looping through each row with a for() loop, but it isn't working as expected, so I am just trying to find out if it something I was doing wrong, or a bug, or something else?

 

If no-one can advise why this is happening then I guess I will have to use the 'for loop' workaround or another solution, but you know when you just want to know *why* something isn't working as you expect?  That is why I posted :)

Link to comment
Share on other sites

Should I report this as a possible bug?  I can't find any evidence that this behaviour has already been reported on the official php bug site.

 

There is evidence of someone else having this same issue : http://www.php.net/manual/en/function.odbc-num-rows.php#77736 (the post that is dated 11-Sep-2007 12:06), but that seems to have been around for ages.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.