Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Oracle Functions : ocifetchstatement

ocifetchstatement

Alias of oci_fetch_all (PHP 4, PHP 5, PECL oci8:1.0-1.2.4)


Code Examples / Notes » ocifetchstatement

waycool

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 ...)

david

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)


lzilber

Similar to the closed bug #9520 reported by g.giunta@libero.it (it did not seem obvious to me):
After a call to OCIFetchStatement, functions OCIColumnName, OCIColumnSize, OCIColumnType, ... will NOT work anymore on the fetched statement.
Explanation (thies@php.net): "...after a cursor is completly read (which is what fechstatement does) this information is no longer valid."


adelac05

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";


larowlan

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'


humberto

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/


phpnet

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.


aries

Don't forget: you must use capital letters as column name.

Change Language


Follow Navioo On Twitter
oci_bind_array_by_name
oci_bind_by_name
oci_cancel
oci_close
OCI-Collection->append
OCI-Collection->assign
OCI-Collection->assignElem
OCI-Collection->free
OCI-Collection->getElem
OCI-Collection->max
OCI-Collection->size
OCI-Collection->trim
oci_commit
oci_connect
oci_define_by_name
oci_error
oci_execute
oci_fetch_all
oci_fetch_array
oci_fetch_assoc
oci_fetch_object
oci_fetch_row
oci_fetch
oci_field_is_null
oci_field_name
oci_field_precision
oci_field_scale
oci_field_size
oci_field_type_raw
oci_field_type
oci_free_statement
oci_internal_debug
OCI-Lob->append
OCI-Lob->close
oci_lob_copy
OCI-Lob->eof
OCI-Lob->erase
OCI-Lob->export
OCI-Lob->flush
OCI-Lob->free
OCI-Lob->getBuffering
OCI-Lob->import
oci_lob_is_equal
OCI-Lob->load
OCI-Lob->read
OCI-Lob->rewind
OCI-Lob->save
OCI-Lob->saveFile
OCI-Lob->seek
OCI-Lob->setBuffering
OCI-Lob->size
OCI-Lob->tell
OCI-Lob->truncate
OCI-Lob->write
OCI-Lob->writeTemporary
OCI-Lob->writeToFile
oci_new_collection
oci_new_connect
oci_new_cursor
oci_new_descriptor
oci_num_fields
oci_num_rows
oci_parse
oci_password_change
oci_pconnect
oci_result
oci_rollback
oci_server_version
oci_set_prefetch
oci_statement_type
ocibindbyname
ocicancel
ocicloselob
ocicollappend
ocicollassign
ocicollassignelem
ocicollgetelem
ocicollmax
ocicollsize
ocicolltrim
ocicolumnisnull
ocicolumnname
ocicolumnprecision
ocicolumnscale
ocicolumnsize
ocicolumntype
ocicolumntyperaw
ocicommit
ocidefinebyname
ocierror
ociexecute
ocifetch
ocifetchinto
ocifetchstatement
ocifreecollection
ocifreecursor
ocifreedesc
ocifreestatement
ociinternaldebug
ociloadlob
ocilogoff
ocilogon
ocinewcollection
ocinewcursor
ocinewdescriptor
ocinlogon
ocinumcols
ociparse
ociplogon
ociresult
ocirollback
ocirowcount
ocisavelob
ocisavelobfile
ociserverversion
ocisetprefetch
ocistatementtype
ociwritelobtofile
ociwritetemporarylob
eXTReMe Tracker