Sets editing mode for the record. In order for a value to be changed, it should be set in edit mode. This locks the record so that other users cannot edit it simultaneously.
bool i5_ edit (resource file [, int mode])
Parameters
file |
IBM i file resource.
|
mode |
Editing mode. • I5_EDIT_ONE leaves edit mode after i5_update() and also after reading or i5_delete(). • I5_EDIT_ALWAYS remains in edit mode until i5_cancel_edit() is called. • I5_EDIT_AUTO is called automatically therefore there is no need to call i5_update() after setting values.
|
Return
True if OK, false if failed.
I5_ERR_PHP_TYPEPARAM |
262 |
Type of element x in parameter -1 must be y. Type z was provided. |
I5_ERR_PHP_NBPARAM_BAD |
263 |
Wrong parameter count |
Detail
• Before any record modification or writing attempt, editing mode must be set using i5_edit function.
• Warning: if the record is already in editing mode or locked by another user, the function will return an I5_ERR_RECORDLOCKED error type. It's important to check this eventuality in the code.
• i5_edit will lock the record until i5_update or i5_cancel_edit is called.
Then, values can be allocated using i5_setvalue.
According to mode, validate updating is also possible by using i5_update function.
Mode:
I5_EDIT_ONE |
Quits editing mode after i5_update function call An i5_delete or a reading will also deactivate. editing mode |
I5_EDIT_ALWAYS |
Keeps in editing mode after i5_update function call To exit, i5_cancel_edit must be called. |
I5_EDIT_AUTO |
Updating is automatic, so, calling i5_update function to validate is unnecessary. |
Note:
Modes I5_EDIT_AUTO and I5_EDIT_ALWAYS can be combined:
$edit = i5_edit($file, I5_EDIT_AUTO | I5_EDIT_ALWAYS);
Example
/* Opening connection and file */
$conn = i5_connect("MY_AS","USER","PASSWORD");
$res = i5_open("EASYCOM/TESTFILE", I5_OPEN_READWRITE);
/* Opening 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");
$ret = i5_update($res);
}
$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 ALL current record values */
$table = array("CODE" => "C-02", "NAME" => "DUPONT", "TYPE" => 3);
$ret = i5_setvalue($ret, $table);
$ret = i5_update($res);
See also
i5_update