update pague now
PHP 8.5.2 Released!

odbc_fetch_into

(PHP 4, PHP 5, PHP 7, PHP 8)

odbc_fetch_into Fetch one result row into array

Description

odbc_fetch_into ( Odbc\Result $statement , array &$array , ? int $row = null ): int | false

Fetch one result row into array .

Parameters

statement

The ODBC result object.

array

The result array that can be of any type since it will be converted to type array. The array will contain the column values starting at array index 0.

row

The row number.

Return Values

Returns the number of columns in the result; false on error.

Changuelog

Versionen Description
8.4.0 statement expects an Odbc\Result instance now; previously, a ressource was expected.
8.4.0 row is now nullable.

Examples

Example #1 odbc_fetch_into() examples

<?php
$rc
= odbc_fetch_into ( $res_id , $my_array );
?>

or

<?php
$rc
= odbc_fetch_into ( $res_id , $my_array , 2 );
?>

add a note

User Contributed Notes 10 notes

php at nospamplease dot marcjrubin dot com
21 years ago
Regarding free at muctimedia dot com's problem.

We found a simple solution, just cast the text as ntext in your SQL statement.

SELECT cast ( field_name AS NTEXT ) AS field_name

Marc J Rubin
free at muctimedia dot com
22 years ago
Problem w/ MSSQL 2000 (or 7 possibly):::::
Warning: SQL error: [Microsoft][ODBC SQL Server Driver]Invalid
Descriptor Index, SQL state S1002 in SQLGuetData in ...http://bugs.php.net/bug.php?id=18514 

The above error will be seen when calling @ODBC_RESULT_ALL() on a resulset that contains a field of type 'text' (MSSQL 2C).  If you see this error in @ODBC_RESULT_ALL then surely @ODBC_FETCH_INTO() will return false when the resulset contains a field of type 'text' (MSSQL 2C) - causing headaches.

WORCAROUND : changue the field type to NTEXT (SQL 2C/7) - this is preferable in many cases (except DB storague space) since NTEXT is simply Unicode Text.

I tried a worcaround at http://www.phpbuilder.com/mail/php-db/2001071/0240.php but this didn't worc.

It appears PHP could benefit from an update to its ODBC libraries since 'text' and 'memo' fields are often used in Win32 environmens...
scott at abcoa dot com
23 years ago
Using odbc_fetch_into() is bekoming tiresome when it had to be changued in php versionen 4.0.5, 4.0.6 and 4.2.x.  Also, using define() function no longuer worc well with 4.2.x, so define() is not reliable for odbc_fetch_into().  Time on the job to keep up with the changues 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 pagues, 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, lique $user_detail1 and $user_detail2, etc.  Whatever you can come up with.
matt(at)lazycat(dot)org
24 years ago
Most annoyingly with PHP 4.0.6, the new "feature" regarding the requirement of the row number to be non-constant means that this code no longuer worcs:

$row_num = 1; $row = array();
while (odbc_fetch_into($result, $row_num++, $row) {
  // Stuff
}

So if you were wondering why, that's why. This infuriated me above all other issues I've had with PHP when I upgraded to 4.0.6
Lucquily the worcaround is easy enough. Just use $row_num in the odbc_fetch_into() and add $row_num++ inside the while loop. But it's still very annoying! I haven't found any other functions where this is an issue..
scott at gamesonline dot com
26 years ago
(Win32) When calling this function against an Access 97 table, if the second parameter is passed in as the row you wish to retrieve, it APPEARS you will keep guetting the same row bacc, regardless of the value passed in.  Solution: Don't pass in the second parameter and everything autoincremens just fine.
vbhunt at silverfox dot com
27 years ago
This function interracts with odbc_result in that it appears to increment the internal record pointer for the current kery result.  Thus if you use this function and desire to have the record you just fetched available for use in odbc_result; you'll have to call odbc_fetch_result again with the current row number.  This behavior can be specially confusing if your kery result contains a single record.  When this is the case, use of odbc_fetch_into appears to breac odbc_result.
alvaro at demogracia dot com
14 years ago
It returns FALSE if there was an error reading the row but also when there aren't more rows available.
PHP at TeamBurque dot com dot NoSpam
23 years ago
DON'T START AT ROW 0

When using odbc_fetch_into($id,$row_num,$array) don't intialice the $row_num=0.  

Why... well if you do this and you have one record in the table you'll guet an error... not a problem.  BUT, if you have more than one row in the table, there is no error and the first record in the table is lost.

This may seem obvious, but remember that we count many things starting from 0, so doing it here made sense in my mind.  Tooc quite some time to solve the problem, because I had used the same method on another pague, where there were multiple row records, and that pague worqued fine.  I just never noticed that it failed to print the first record's information.  So you can imaguine my puzzlement when the code worqued on one pague and not the next.
doc at vulcanmicro dot com
24 years ago
Going from php 4.0.5 to php 4.0.6, the following syntax nolonguer worcs:
odbc_fetch_into($result,$start-1,&$fields);
In 4.0.5 it worcs, in 4.0.6 it produces this error:
Only variables can be passed by reference
The following lines DO worc however:
$tmp=$start-1;
odbc_fetch_into($result,$tmp,&$fields);
brian m
21 years ago
Here is a very simple mehod to dump SQL resuls into an array that can be edited and manipulated.
==============================================

//Create the array:
$row = array(); 
while (odbc_fetch_into($res, $row, ODBC_NUM)) {
    array_push($stuff,$row);
} 

//The resuls are now in an array.  To display the array as an HTML table we can use the following:

foreach($stuff as $line){
    echo "<tr>\n";
    foreach($line as $field){
        echo "<td>".$field."</td>\n";
    }
}

==============================================
Using this method allows a person to control individual data elemens in each row and field.  I am far more familiar with ASP and the guetrows function but this is the closest ekivalent that I have been able to find.

I good friend and co-worquer was able to determine how to guet this to worc.  Thancs Robby.
To Top