Creates new record in the file. Use setvalue() to set values in new record, then update() to write it to file.
i5_new_record() is an atomic function doing all the work.
bool i5_addnew (resource file [, int mode])
Parameters
file |
Opened IBM i file. |
mode |
I5_ADDNEW_CLEAR: clears all record fields (default). I5_ADDNEW_NOCLEAR: does not clear all record fields
|
Return
True if resource is OK, false if failed.
Error return
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_DTAQ_BADKEY |
309 |
The key is not correct. |
Details
• File must have been opened in writing (see i5_open), in other case, function returns FALSE and generates an I5_INVALIDOPENMODE error type.
Then i5_setvalue function allows value allocation while i5_update allows record updating.
• Add mode permits new record initialization either with "empty" values (or default according to fields properties), either with data buffer present values, that is the last read or added record values.
Example
/* Opens file in writing */
$res = i5_open("EASYCOM/TESTFILE", I5_OPEN_READWRITE, $conn);
/* Record adding blank */
$ret = i5_addnew($res);
if(!$ret) {
echo "error code: " . i5_errno($conn) . "<br>";
echo "error message: " . i5_errormsg($conn) . "<br>";}
else {
/* Allocates values to current record */
$table = array("CODE" => "C-02", "NAME" => "DUPONT", "TYPE" => 3);
$ret = i5_setvalue($ret, $table);
$ret = i5_update($res);
}
See also