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)
Parameters
file |
IBM i file resource.
|
field |
Field identified by name or position.
|
value |
Value for the field.
|
values |
Array with “key=>value” pairs, describing fields to change and their new values.
|
Return
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. |
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 according to field parameter setting. Index, name or table can be used as parameter.
If using table, it may be an associative table with key and value fields:
$table = array("CODE" => "C-02", "NAME" => "DUPONT", "TYPE" => 3);
I may be also an indexed table. In this case order must be fully respected:
$table = array('C-105', 'DUPOND', 'Jean', 'Avenue du Québec', 'Les Ulis', 3, 'FR');
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