php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38784 odbc_fetch_row call
Submitted: 2006-09-11 21:48 UTC Modified: 2006-09-13 20:02 UTC
From: jkeagle at knology dot net Assigned:
Status: Not a bug Package: ODBC related
PHP Version: 4.4.4 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
3 + 24 = ?
Subscribe to this entry?

 
 [2006-09-11 21:48 UTC] jkeagle at knology dot net
Description:
------------
I'm having a problem getting 'odbc_fetch_row' to return true. Therefore, I am unable to fetch each row of my table. Is there something I'm leaving out in my code? I've tried everything I can think of. Please help.  Thank you.  

Reproduce code:
---------------
$sql = "SELECT PARAMETER_ID, DESCRIPTION from MDR_PARAM"; 
$res = odbc_exec($conn, $sql);

$num_rows   = odbc_num_rows($res);
$num_fields = odbc_num_fields($res); 

$parameter_counter = 0;

if(odbc_fetch_row($res, 0))
    echo("odbc_fetch_row: SUCCESS ...\n\n");
else
    echo("odbc_fetch_row: FAILURE ...\n\n");

while(odbc_fetch_row($res)) {
    $param_id    = odbc_result($res, "PARAMETER_ID");
    $description = odbc_result($res, "DESCRIPTION");

    $mdr_parameters[$description] = $param_id;
    $parameter_counter++;
}
$r = odbc_free_result($res);

Expected result:
----------------
I would have expected "SUCCESS" to be output as opposed the "FAILURE" following the 'if' statement. And, I would have expected to fall into the 'while' loop, but to no avail.  

Actual result:
--------------
odbc_fetch_row: FAILURE ...

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-11 21:51 UTC] jkeagle at knology dot net
Note: num_rows & num_fields were output and return valid numbers.
 [2006-09-12 09:33 UTC] tony2001@php.net
>odbc_fetch_row($res, 0)

The row number is 1-based.
 [2006-09-12 13:40 UTC] jkeagle at knology dot net
Could you be more specific?
 [2006-09-12 14:59 UTC] keagle at westar dot com
By stating that the row number is "1-based", do you mean that rows are indexed (1 .. last)? If so, this doesn't help answer my question. The call returns false(0) regardless of the parameters passed into the call (1 or 0). Why is it that I can't get a positive value returned out of this call? It doesn't make sense. odbc_fatch_row($res) always returns a negative value and odbc_result won't return anything I can use.
 [2006-09-12 16:45 UTC] tony2001@php.net
Use odbc_errormsg() to get the reson why it fails.
 [2006-09-12 18:04 UTC] jkeagle at knology dot net
I tried the odbc_errormsg() call and got an empty string. I also tried odbc_error() and got the same result. 
The problem is that a negative value is returned for each call to odbc_fetch_row as if there are no rows to fetch. What is misleading is that I can execute odbc_num_rows($res) and get 662, which is what I expected to get. Also, a call to odbc_num_fields($res) was called and returned the expected value of 2. What I don't understand is why I can't "fetch a row" out the same result variable ($res). Everytime I make a call to odbc_fetch_row($res), a negative value (0) is returned.
 [2006-09-13 15:38 UTC] kalowsky@php.net
Why are you trusting odbc_num_rows?  

And fix your odbc_fetch_row call.  
 [2006-09-13 16:59 UTC] jkeagle at knology dot net
If I knew how to fix the odbc_fetch_row call I wouldn't have submitted the problem. Thanks for nothing.
 [2006-09-13 20:02 UTC] kalowsky@php.net
While I agree the response wasn't terribly helpful, this also isn't a support forum.  There are better avenues for that where functionality can be explained.

Currently, you've written very little that has shown a bug in PHP itself (I'll cede a bit better documentation as a tangential to the original statement).  
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 21:01:28 2024 UTC