PreviousNext
Help > API Functions > Native database access > i5_fetch_row, i5_fetch_array, i5_fetch_assoc, i5_fetch_object
i5_fetch_row, i5_fetch_array, i5_fetch_assoc, i5_fetch_object

 

Fetches a result row from a result set or a file and returns the data in various formats.

 

       array i5_fetch_row (resource result, int option)

       array i5_fetch_ array (resource result, int option)

       array i5_fetch_ assoc (resource result, int option)

       array i5_fetch_ object (resource result, int option)

 

 

 

Parameters

 

result

Result set or Open file ID

option

Cursor movement option.

 

Valid options are:

I5_READ_NEXT

Read next record, or the record requested by a previous call to i5_seek() or i5_data_seek().
If the previous function call for the result set or the file, was i5_seek() or i5_data_seek(), then i5_fetch_xxxx reads the record requested by this previous function.
Otherwise, the function reads the next record in the result set or file.

I5_READ_PREV

Read previous record

I5_READ_FIRST

Read the first record

I5_READ_LAST

Read the last record

I5_READ_SAME

Read the current record. Cursor position is not moved.

 

 

I5_READ_SEEK

Read current record

 

Any attempt to read out of file limits will return NULL and create an error I5_ERR_BEOF type.

 

Return

Function i5_Fetch_xxx() return an array/object or FALSE in case of error.

The format of array returned varies with the called function:

 

i5_fetch_row

Get a result row as an enumerated array.

I5_fetch_array

Fetch a result row as an associative array, and numeric array.

i5_fetch_assoc

Fetch a result row as an associative array.

i5_fetch_object

Fetch a result row as an object.

 

Error returned

I5_ERR_MEMALLOC

3

Not enough memory

I5_ERR_PHP_HDLDFT

256

No default connection found.

I5_ERR_PHP_OPTIONSTYPE

259

The type of " I5_OPTIONS_ALIAS" option must be x and not x

I5_ERR_PHP_OPTIONSNUMBER

260

Option number -1 is unknown.

I5_ERR_PHP_TYPEPARAM

262

Type of element x in parameter -1 must be y. Type z was provided.

I5_ERR_PHP_GETPARAM

275

specific message

 

Details

i5_fetch_xxxx functions move the pointer according to the specified option, read the data from the record set or file and fill up the result array.

To change the current cursor position in the result set or file, use functions i5_seek or i5_data_seek,before to fetch the row.

Warning: i5_fetch_xxx() does not read blob fields. See i5_getblob function.

 

 

Example

 

 

/* Page selection and reading */

$file = i5_open('EASYCOM/NCLIENT');

if (is_bool($file)) trigger_error('i5_open error : '.i5_errormsg(), E_USER_ERROR);

 

$first = array('CNOM' => 'D');

$last = array('CNOM' => 'F');

 

$ret = i5_range_from($file, true, $first);

if (!$ret) trigger_error('i5_range_from error : '.i5_errormsg(), E_USER_ERROR);

 

$ret = i5_range_to($file, false, $last);

if (!$ret) trigger_error('i5_range_to error : '.i5_errormsg(), E_USER_ERROR);

 

echo 'i5_fetch_row : <BR>';

i5_seek($file, I5_FIRST);

 

while ($tab = i5_fetch_row($file)) {

printf('%s (%s)<BR>', $tab[3], $tab[2]);

}

 

echo '<BR>i5_fetch_array : <BR>';

i5_seek($file, I5_FIRST);

 

$tab = i5_fetch_array($file, I5_READ_SEEK);

 

while ($tab) {

printf('%s (%s) : ', $tab['CPREN'], $tab['CNOM']);

printf('%s (%s)<BR>', $tab[1], $tab[2]);

$tab = i5_fetch_array($file, I5_READ_NEXT);

}

 

echo '<BR>i5_fetch_assoc : <BR>';

$tab = i5_fetch_assoc($file, I5_READ_FIRST);

 

while ($tab) {

printf('%s (%s)<BR>', $tab['CPREN'], $tab['CNOM']);

$tab = i5_fetch_assoc($file, I5_READ_NEXT);

}

 

See also

 

i5_result

i5_getblob

i5_seek

i5_data_seek