i5_setvalue

 

Changes the value of the current record. The record should be in edit mode after i5_edit() or created by i5_addnew().

 

Syntax N° 1:

Bool i5_setvalue

( resource file
, int/string field, mixed value )


Syntax N° 2:

Bool i5_setvalue

( resource file
, array values )

 

Detail

 

This function is used after editing is set with i5_edit function or after an addition with i5_addnew.

If mode is automatic (I5_EDIT_AUTO), updating is performed directly, otherwise i5_update function must be called to validate it.

One or more current record fields can be modified setting field index, name or table as parameter.

 

If using table, it may be an associative table fields to modify name as key and each field value as values, in respect of their types.

$table = array("CODE" => "C-02", "NAME" => "DUPONT", "TYPE" => 3);

or an indexed table as well, in this case order must be fully respected:

$table = array('C-105', 'DUPOND', 'Jean', 'Avenue du Québec', 'Les Ulis', 3, 'FR');

Code must be index 0 field, index 1 name, index 5 type.

 

 

Parameters

 

file

i5 file resource.

 

field

field Field identifier by name or position.

 

value

Value for the field.

 

values

Set of key=>value parts describing fields to change and their new values.

 

 

Returns:

True if OK, false if failed.

 

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_GET_SYSVAL

297

The command returned an error: x.

 

 

Example

 

 

/* Opening file in writing */

$res = i5_open("EASYCOM/TESTFILE", I5_OPEN_READWRITE);

$rec = i5_fetch_row($res, I5_READFIRST);

 

 

/* Activates current record edition mode */

 

$ret = i5_edit($res, I5_EDIT_ONE);

if (!$ret) {

    echo "error code: " . i5_errno($conn) . "<br>";

    echo "error message: " . i5_errormsg($conn) . "<br>";

    }

else {

 

    /* Modifies ONE current record field value */

    $ret= i5_setvalue($ret, "CODE", "C-02");

/* or i5_setvalue($ret, 0, "C-02"); */

    $ret = i5_update($res);

    $ret = i5_edit($res, I5_EDIT_ONE);

 

 

    /* Modifies MANY current record field values */

    $table = array("CODE" => "C-02", "NAME" => "DUPONT", "TYPE" => 3);

    $ret= i5_setvalue($ret, $table);

    $ret = i5_update($res);

    }

 

 

    /* Modifies the 7 first current record values */

$table = array('C-105', 'DUPOND', 'Jean', 'Avenue du Québec', 'Les Ulis', 3, 'FR');

    $ret= i5_setvalue($ret, $table);

    $ret = i5_update($res);

    }

 

 

 

See also

 

i5_addnew

i5_edit

i5_update