ocifetchstatement

(PHP 3 >= 3.0.8, PHP 4, PHP 5)

ocifetchstatement -- Выбирает все строки из результата запроса в массив

Описание

int ocifetchstatement ( resource stmt, array &output [, int skip [, int maxrows [, int flags]]] )

Замечание: В PHP 5.0.0 и выше ocifetchstatement() является алиасом oci_fetch_all(). Вы можете продолжать использовать это имя, однако это не рекомендуется.

См. также oci_fetch_array(), oci_fetch_assoc(), oci_fetch_object(), oci_fetch_row().



ocifetchstatement
larowlan at nospam dot com
26-Jun-2005 04:46
Not all column names are converted to upper case array keys. If you use double quotes around column aliases these retain their original case when converted to array keys.

Eg Select count(*) "record count" from table

will return an array with key 'record count' not 'RECORD COUNT'
phpnet at rafael dot eti dot br
09-Sep-2004 07:47
Humberto, from the previous note misunderstood the function ocifetchstatement. The default value of the last parameter is OCI_FETCHSTATEMENT_BY_COLUMN. That is the reason that $rows has the value 20 and count($arr) has the value 13 in:

$rows=ocifetchstatement ($st, &$arr, 0, 20);

It happens because his query probably had 13 columns.

That way, count($arr[0]) would have the value 20 that he expected of count($arr).

So,

$rows=ocifetchstatement ($st, &$arr, 0, 20);

is equivalent to

$rows=ocifetchstatement ($st, &$arr, 0, 20, OCI_FETCHSTATEMENT_BY_COLUMN);

and it is not equivalent to

$rows=ocifetchstatement ($st, &$arr, 0, 20, OCI_FETCHSTATEMENT_BY_ROW);

I hope this helps to avoid some confusion about ocifetchstatement.
humberto at humbertosilva dot com
09-Jul-2004 07:06
I had a problem with ocifetchstatement, it didn't returned nor more or less than 13 rows whatever the skip or num_rows was set to....

I found that it has a bug, you MUST specify the last parameter, so i added OCI_FETCHSTATEMENT_BY_ROW to the function call and it works fine.

Hope this helps someone out there ...

With:
           $rows=ocifetchstatement ($st, &$arr, 0, 20);

Returns:
           $rows 20
           count($arr) 13 !!! (should be 20)

Now here's the working version:

With:
           $rows=ocifetchstatement ($st, &$arr, 0, 20, OCI_FETCHSTATEMENT_BY_ROW);
Returns:
           $rows 20
           count($arr) 20

wich are the right values.

Regards,

Humberto Silva
http://www.humbertosilva.com/
david at boeke dot com
16-Dec-2003 10:17
The Skip and MaxRows parameters were not added until version 4.2.1.
Previous versions of php used this syntax:

           int ocifetchstatement ( resource stmt, array &output)

The function also took a third parameter that was not documented.  ( I assume that it was a flag)
adelac05 at sprintspectrum dot com
12-Mar-2003 04:40
One thing I found with this:

If you have two tables with the same column names, you will run into problems when displaying them, i.e:

$sql = "select a.name, b.name, c.phone
from table1 a, table2 b, table3 c";

php will overwrite the a.name display cell with the b.name value.  So you wanted three cells to display and you are only getting two.  i.e.

What you wanted:

----------------------------------------
| Bob          | Jones    | 555-555-5555 |
----------------------------------------

What you got:

-----------------------------------------
| Jones        | 555-555-5555 |              |
-----------------------------------------

Resolution:  rename your table column names as they come in.

$sql = "select a.name, b.name AS NAME2, c.phone
from table1 a, table2 b, table3 c";
lzilber at hotmail dot com
03-Aug-2001 02:19
Similar to the closed bug #9520 reported by g.giunta@libero.it (it did not seem obvious to me):<br>
After a call to OCIFetchStatement, functions OCIColumnName, OCIColumnSize, OCIColumnType, ... will NOT work anymore on the fetched statement.<br>
Explanation (thies@php.net): "...after a cursor is completly read (which is what fechstatement does) this information is no longer valid."
</p>
aries at bsd dot hu
29-Dec-2000 02:41
Don't forget: you must use capital letters as column name.
waycool at audioload dot com
31-Oct-1999 01:44
Watch out for select statements which have columns with the same name (e.g. select a.name, b.name from ...) because the later results will wipe out the previous $data["name"] values. One way to get around this is to use aliases (e.g. select a.name as a_name, b.name as b_name ...)

<ocifetchintoocifreecollection>
 Last updated: Tue, 15 Nov 2005