Re: oracle: fetch a query result into an array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To make your life much easier, I recommend using PEAR DB. The function calls are very easy and work for any DBMS (no remembering DB specific calls :-)). It also gives you lots of added functionality, such as fetching of an entire result set at once, fetching only one row, or even fetching one column quickly and without the need to worry about freeing your resources. Used right, you don't have to worry about memory leaks or even the DB backend you're using.

http://pear.php.net/package/DB
http://pear.php.net/manual/en/package.database.php

Torsten Lange wrote:

Hello,
I'm a php beginner and not succeed in fetching an oracle query result into an array. I want to load the colum names of a table (from an Oracle9i) into a <select>-field. There is something working, but only the last column name appears in the select field and is wraped by each letter.
For instense acw_fid_lab:
___
|non|
|all|
|A |
|C |
.
. and so on.


What are my mistakes? If anyone could suggest me how to solve it or using a better approach...

Thank you, Torsten
---------------------------------------------------
My last version (I also tried OCIFetchInto before):
---------------------------------------------------
function fill_select($table_name)
   {
   $connect = @OCILogon("", "", "");

if(!$connect)
{
$err_oci = OCIError();
echo "(2) No connection - OCIError(): &nbsp;&nbsp;&nbsp;".$err_oci["message"];
echo "<p>";
}
else
{
$sql_table_names = "SELECT column_name FROM user_tab_columns
WHERE table_name = '".$table_name."'";
$stmt = OCIParse($connect, $sql_table_names);
OCIExecute($stmt);


         $column_name = array();
         $counter = 0;

         while(OCIFetch($stmt))
            {
            $column_name = OCIResult($stmt,'COLUMN_NAME');
            $counter++;
            }

         if($counter == 0)
            {
            $column_name[0] = "nothing found";
            }
         OCIFreeStatement($stmt);
         OCILogOff($connect);
         return($column_name);

         }
   }

# This is a cut-out from that file I call the function from
echo "   <td>\n";
echo "       <select name=\"chemistry\" size=\"12\" multiple>\n";
echo "       <option>none</option>\n";
echo "       <option>all</option>\n";
             $table_name = "AN_CHEMISTRY_WATER";
             $count = (int) count_table_columns($table_name);
             $column_names = fill_select($table_name);
             for($i=1; $i<=$count; $i++)
                {
                 echo "<option>",$column_names[$i],"</option>\n";
                }
echo "       </select>\n";
echo "   </td>\n";


--
--
paperCrane <Justin Patrin>

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux