note 90531 added to function.odbc-fetch-array

From: Date: Mon, 27 Apr 2009 07:35:13 +0000
Subject: note 90531 added to function.odbc-fetch-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-153800@lists.php.net to get a copy of this message
I've been toying around, trying to do this as simple, safe and fast and possible. <?php /* Setup ODBC Connection */ if(!$odbc['connection'] = odbc_connect('DNS','USER','PASS')) { exit("Connection Failed<br />\n"); } else { echo("Connected<br />\n"); } /* Set which table to use */ $odbc['table'] = "table"; /* Fetches The Fieldnames */ if($result = odbc_exec($odbc['connection'],"select * from $odbc['table'];")) { for($i = 1;$i <= odbc_num_fields($result);$i++) { $odbc['rows']['fields'][$i] = odbc_field_name($result,$i); } unset($i); odbc_free_result($result); } else { exit("Error in SQL Query"); } /* Fetch Table Contens and Instert it into a Array by Fieldnames */ if($result = odbc_exec($odbc['connection'],"select * from $odbc['table'];")) { $x = 1; while(odbc_fetch_row($result)) { for($y = 1;$y <= odbc_num_fields($result);$y++) { $odbc['rows'][$x][$odbc['rows']['fields'][$y]] = odbc_result($result,$y); } unset($y); $x++; } unset($x); odbc_free_result($result); } else { exit("Error in SQL Query"); } /* Close The Connection */ if(odbc_close($odbc['connection'])) { odbc_close($odbc['connection']); } /* Print The Array */ if(!empty($odbc['rows'])) { print_r($odbc['rows']); } ?> ---- Server IP: 80.67.2.2 Probable Submitter: 89.253.82.225 ---- Manual Page -- http://www.php.net/manual/en/function.odbc-fetch-array.php Edit -- https://master.php.net/note/edit/90531 Del: integrated -- https://master.php.net/note/delete/90531/integrated Del: useless -- https://master.php.net/note/delete/90531/useless Del: bad code -- https://master.php.net/note/delete/90531/bad+code Del: spam -- https://master.php.net/note/delete/90531/spam Del: non-english -- https://master.php.net/note/delete/90531/non-english Del: in docs -- https://master.php.net/note/delete/90531/in+docs Del: other reasons-- https://master.php.net/note/delete/90531 Reject -- https://master.php.net/note/reject/90531 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#153800) next »