ora_fetch

(PHP 3, PHP 4, PHP 5 <= 5.1.0RC1)

ora_fetch -- 从一个游标中取得一行数据

描述

bool ora_fetch ( resource cursor )

从指定的游标中取回一行数据,该行数据由参数 cursor 指明。

如果取得一行数据则返回 TRUE,如果没有取得数据或产生错误,则返回 FALSE。 如果有错误,错误的细节能够使用 ora_error()ora_errorcode() 函数取得。如果没有错误,函数 ora_errorcode() 将返回0。

参见 ora_parse()ora_exec(), 和 ora_do()


add a note add a note User Contributed Notes
god at danielhauser dot com
09-Jun-2003 11:36
summary: ;-)

If you are using the ora_do() function, you must use do { ... } while(ora_fetch($curs));
because of ora_do() automaticaly fetches the first row.

If you are using
$cur=Ora_Open($db_conn);
Ora_Parse($cur,$sql,0);
Ora_Exec($cur);

you must use while(ora_fetch($curs)) { ... }
because the ora_exec doesn't fetch any row.
forever at klub dot chip dot pl
28-Mar-2003 07:36
Not only when there is only one row... the described problem occurs for the FIRST row!!! even if there is 1000 rows the first one will not be displayed so described example with 'do' solve this problem for all cases.
rrosso at zalem dot com
12-Jul-2002 04:36
Little update to abovementioned. $numCols would not work.

       while(ora_fetch($curs1) == 1){                          // WHILE THERE IS A ROW
               for($i=0;$i<ora_numcols($curs1);$i++){          // PARSE THROUGH THE COLUMNS
               printf("%s", ora_getcolumn($curs1,$i));        //  PRINT THE RESULTS
               }
       }
22-Feb-2002 04:01
Obviously Daniel has no idea what he is talking about!  ora_fetch() is a wonderful tool for extracting a row from the data base. Here is how:

  while(ora_fetch($cursor) == 1){    // WHILE THERE IS A ROW
     for($i=0;$i<$numCols;$i++){    // PARSE THROUGH THE COLUMNS
       echo ora_getcolumn($cursor,$i);      //  PRINT THE RESULTS
     }
   }                                    // NEXT ROW

There are many ways to modify the above code to get the desired result, but this is a basic way to parse through all of the result set.
dmuth at ot dot com
15-Jan-2000 07:54
Try using ora_fetch_into($cursor, &$results) to get the row into an array.  Yes, you need the "&" sign before the name of the variable to fetch into so that it is passed by reference and can be modified in the function. 

You should also be aware that when calling this function multiple times (like within a loop) that the array is NOT initialized, which could lead to some "ghosting" of data.  You need to initialize the array yourself, prefarably with the array() function.