Re: oracle: fetch a query result into an array
| From: | Justin Patrin | Date: | Wed, 18 Feb 2004 21:51:15 +0000 |
| Subject: | Re: oracle: fetch a query result into an array | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-33014@lists.php.net to get a copy of this message | ||
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)-- -- paperCrane <Justin Patrin>{ $err_oci = OCIError(); echo "(2) No connection - OCIError(): ".$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";