PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<odbc_executeodbc_fetch_into>
view the version of this page
Last updated: Thu, 21 Aug 2003

odbc_fetch_array

(PHP 4 >= 4.0.2)

odbc_fetch_array --  Fetch a result row as an associative array

Description

array odbc_fetch_array ( resource result [, int rownumber])

Warning

This function is currently not documented; only the argument list is available.



add a note add a note User Contributed Notes
odbc_fetch_array
andrea dot galli at acotel dot com
18-Apr-2003 01:01
The next_record () function, checks if there is the odbc_fetch_array function in the installed version of php.
If it doesn't exist, it  call another function named odbc_fetch_array() made by me that it returns the same result.

while(list($Record1, $Record2) = $next_record($Query_ID))
{
   echo("$Record1 $Record2\n");
}

---

function next_record($Query_ID)
{
   if(function_exists(odbc_fetch_array))
   {
      $Record = odbc_fetch_array($Query_ID);
   }
   else
   {
      $Record = $odbc_fetch_array($Query_ID);
   }

   $Row += 1;

   $stat = is_array($Record);

   if(!$stat)
   {
      odbc_free_result($Query_ID);
      $Query_ID = 0;
   }

   return $Record;
}

function odbc_fetch_array($Query_ID, $RowNumber = -1)
{
   if($RowNumber < 0)
   {
      odbc_fetch_into($Query_ID, $rs);
   }
   else
   {
      odbc_fetch_into($Query_ID, $rs, $RowNumber);
   }

   if(isset($rs))
   {
      return $rs;
   }
   else
   {
      return false;
   }
}
garrieDOTpowersATkclDOTacDOTuk
21-Oct-2002 08:45
This function will return all of the rows returned by a query in an array.

$resultSet['fieldNames'] contains an array of fieldnames keyed by field number

$resultSet[n], where n is the record number, contains an associative array keyed on fieldname.

- Garrie
----------------------------------------

function odbc_fetch_resultset($resID)
{
/* Return all the rows returned by a query in an array.
   
*/

   $resultSet=array();

// Assign the field names to $resultSet['fieldNames']

   $fCount = odbc_num_fields($resID);
   for ($i=1; $i<= $fCount; $i++){
      $fNames[$i] = odbc_field_name($resID, $i);
   }

   $resultSet['fieldNames']=$fNames;

// Assign the records

   for ($i=1; odbc_fetch_row($resID,$i); $i++){

      $record=array();
      for ($j = 1; $j <= $fCount; $j++){
         $fName = odbc_field_name($resID, $j);
         $record[$fName]=odbc_result($resID, $j);
      }

      $resultSet[$i]=$record;
   }
   
   
   return ($resultSet);

}
scott at abcoa dot com
03-Jul-2002 01:40
Using odbc_fetch_into() is becoming tiresome when it had to be changed in php version 4.0.5, 4.0.6 and 4.2.x.  Also, using define() function no longer work well with 4.2.x, so define() is not reliable for odbc_fetch_into().  Time on the job to keep up with the changes is ill-advised.  Turned out the better solution is to use odbc_fetch_array and not have to deal with the hassle of updating the database, web pages, etc.  It is worth the time in the long run.

--clip-- (old script)
define(CUSTOMER_ID,0);
define(CUSTOMER_NAME,1);

//$rows = 1;

if (odbc_fetch_row($result))
{
//odbc_fetch_into($result,1,&$user_detail); //php 4.0.5
//odbc_fetch_into($result,$row,$user_detail); //php 4.0.6
odbc_fetch_into($result,$user_detail,1);  //php 4.2.x
   echo $user_detail[CUSTOMER_ID];
} else {
   echo "Failed!";
}
--clip--
//#########################################
--clip-- (new script)
if (odbc_fetch_row($result))
{
   while($user_detail = odbc_fetch_array($result) ) {
      echo $user_detail[CUSTOMER_ID];
   }
} else {
   echo "Failed!";
}
--clip--

This is pretty useful when we keep adding columns to the database table.  If you combine two tables and have two columns with the same column name, then you'll need to have two seperate array, like $user_detail1 and $user_detail2, etc.  Whatever you can come up with.
michael dot fallise at chello dot be
02-Apr-2002 09:51
Just a note about the odbc_fetch_array function of Martin (above).
The function actually works fine except when your resultset is empty (where $rs_assoc is not defined).
To avoid this just define $rs_assoc as an array before the foreach like this :
$rs_assoc = Array();

That should do the trick
cenix at home dot nl
21-Feb-2002 12:31
if you have trouble getting odbc_fetch_array() working, try:

odbc_fetch_into($result, $myarray);
instead of
$myarray = odbc_fetch_array($result);

it worked fine for me.
martin at NOSPAMkouba dot at
06-Feb-2002 07:46
since this is not available at 4.1 at the moment you can try this (put it in an extra file and include it to avoid an error when the function will exist on the next php update):

if (function_exists(odbc_fetch_array))
  return;

function odbc_fetch_array($result, $rownumber=-1) {
  if (PHP_VERSION > "4.1") {
    if ($rownumber < 0) {
      odbc_fetch_into($result, &$rs);
    } else {
      odbc_fetch_into($result, &$rs, $rownumber);
    }
  } else {
    odbc_fetch_into($result, $rownumber, &$rs);
  }
  foreach ($rs as $key => $value) {
    $rs_assoc[odbc_field_name($result, $key+1)] = $value;
  }
  return $rs_assoc;
}

<odbc_executeodbc_fetch_into>
 Last updated: Thu, 21 Aug 2003
show source | credits | sitemap | mirror sites 
Copyright © 2001-2003 The PHP Group
All rights reserved.
This mirror generously provided by: http://php.mirrors.ilisys.com.au/
Last updated: Sat 01 Nov 2003 04:13:36 EST EST