1 Reply Latest reply on Apr 11, 2011 3:03 PM by 633274

    How to fetch the whole table at once!


      This question is regarding working with PHP-Oracle.

      To display result of a query we use -
      oci_result($statement,'COLUMN_NAME') function.. to demonstrate the use of this function please see the following snippet -
      Let's suppose we are fetching EMPNO column from EMP table from scott's schema -

      PHP Code:


      $query="select * from emp";



      while (oci_fetch($stmt))


      echo oci_result($stmt,'EMPNO');


      Now this code displays all rows under EMPNO column.. but suppose if I do not know how many columns are there in a table and want to display all columns along with all rows, how will I do that?

      Urgent help required please..

      Thanks in advanced
        • 1. Re: How to fetch the whole table at once!
          IMHO, the simplest way is to retrieve the complete row as array and use a simple foreach() loop:

          - oci_fetch_assoc() - Returns the next row from a query as an associative array
          - oci_fetch_row() - Returns the next row from a query as a numeric array

          Further reference:
          - http://es2.php.net/manual/en/function.oci-fetch-assoc.php
          - http://es2.php.net/manual/en/function.oci-fetch-row.php
          - http://es2.php.net/manual/en/control-structures.foreach.php


          I had misread your question. Try http://es2.php.net/manual/en/function.oci-fetch-all.php instead.

          Edited by: kAlvaro on Apr 11, 2011 5:03 PM