note 90531 deleted from function.odbc-fetch-array by danbrown
| From: | danbrown@php.net | Date: | Mon, 27 Apr 2009 14:24:42 +0000 |
| Subject: | note 90531 deleted from function.odbc-fetch-array by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153812@lists.php.net to get a copy of this message | ||
Note Submitter: anuga at anuga dot se
----
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']);
}
?>