note 56802 added to function.odbc-fetch-array
| From: | tim at tmcode dot com | Date: | Thu, 15 Sep 2005 15:07:01 +0000 |
| Subject: | note 56802 added to function.odbc-fetch-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-95229@lists.php.net to get a copy of this message | ||
Depending on the odbc driver/operating system you are using, odbc_fetch_array might not be defined.
(ie if you used --with-custom-odbc you may be out of luck). The following can be safely added to
define the odbc_fetch_array function if doesn't exist already. Unlike some of the other
examples contributed here, this one will create the numeric keys and the text keys. This function
is definitely not very optimal because it has to check the number of fields and field names each
time a row is pulled. Often you will be looping through a result set and there is no need to pull
this information each time. It could probably be improved by caching the result of these functions
but I'll leave that as an exercise for someone else... :)
if(!function_exists("odbc_fetch_array"))
{
function odbc_fetch_array($res)
{
// make sure to pass back the false if we are out of rows
if(!odbc_fetch_row($res)) return false;
$row=array();
// populate the row array
$numfields=odbc_num_fields($res);
for($i=1; $i<=$numfields; $i++)
{
//odbc starts its indice at 1 but since I am
// trying to emulate the functionality of *_fetch_array
// for other dbs (ie mysql) I'm going to decrement my
// my numeric indice by 1. This might not be what
// you are after in which case get rid of the -1
$row[odbc_field_name($res,$i)]=$row[$i-1]=odbc_result($res,$i);
}
return $row;
}
}
----
Manual Page -- http://www.php.net/manual/en/function.odbc-fetch-array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56802
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56802&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56802&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56802&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56802&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56802&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+56802&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56802&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56802&report=yes
Search -- http://master.php.net/manage/user-notes.php