PreviousNext
Help > API Functions > Native database access > i5_open
i5_open

 

Opens native IBM i file.

 

     string i5_open (string filename [, int mode ][, resource connection])

 

 

Parameters

 

filename

File name. File name can have several formats:

     FILE

     LIBRARY/FILE

     FILE(MEMBER)

     LIBRARY/FILE(MEMBER)

When library is not specified, the file must be present in the job library list (*LIBL).

mode

 

File mode to use:

I5_OPEN_READ

Open the file for read only (default)

 I5_OPEN_READWRITE

Open file for reading and writing

 I5_OPEN_COMMIT

Open journalize

 I5_OPEN_SHRRD

Shared reading

 I5_OPEN_SHRUPD

Shared updating

 I5_OPEN_SHRNUPD

Sharing without updating

 I5_OPEN_EXCLRD

Open Exclusive; Read allowed

 I5_OPEN_EXCL

Open Exclusive

connection

Connection - result of i5_connect

 

 

Return

Resource, if "open" is successful, false otherwise.

 

I5_ERR_DESC_WRONG_DATAOP

41

Wrong operation on a data field of a description

I5_ERR_PARSEXML

42

Internal error; please contact Aura Equipements.

error number 42

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.

 

Details

 

         A file must be opened with i5_open function prior to access it (reading or writing).
Function i5_open() returns an ID to be used as parameter for reading, updating or adding, research,…operations.

         The file to open can be a physical or logical file.

 

         It's more efficient to use job *LIBL by giving only the file name, without library name, if of course the user is entitled to necessary and coherent rights to opening mode and path.

The current library list can be previously changed by ADDLIBLE commands call issued by i5_remotecmd .

 

         You can qualify the path by providing a library name in the form: LIBRARY/NAME.

         The file to open can have been overridden by a previous OVRDBF command call, issued by i5_remotecmd .
It can also be filtered by an OPNQRYF command call.

 

         If the file doesn’t have any description, as for a 36 format file, an external description can be applied.
The external description is given at the end of the file name, prefixed by "*FMT=".
Example: LIB36F/MYFILE *FMT=DATALIB/DESC36L1

 

         Opening option may be combined using PHP usual syntax and "|" (pipe) symbol.
OPEN_READ or I5_OPEN_READWRITE modes are required to be combined with other modes.

To open a file in reading/writing, under commitment control, in exclusive mode:

i5_open("EASYCOM/SP_CUST", I5_OPEN_READWRITE | I5_OPEN_COMMIT | I5_OPEN_EXCL)

 

         Procedures and Data Queue:

Easycom uses files description to access stored procedures and data queues (see Manufacturer DTAQ-RPC). Principle is to describe all parameters (names, nature, types) stored in Easycom proper files (YPROCHDR and YPROCPARMS).

Opening procedure syntax is *PGM/name_procedure

Opening data queue syntax is *DTAQ/name_dataqueue.

 

 

  

Examples

 

 

/* Opens a file only in reading */

$file_client = i5_open("PROD/CLIENTS");

if(is_bool($file_client))

    {

                   print_r("i5_open error : ".i5_errormsg().'<br/>');

                   $failures++;

    }

 

 

/* Opens a file only in writing */

$file_web = i5_open("PROD/WEB", I5_OPEN_READWRITE);

 

 

/* Opens a file in *LIBL or *CURLIBL */

$file_lib = i5_open("TEST");

$file_clib = i5_open("*CURLIBL/TEST");

 

 

/* Opens a particular member */

$file_fact = i5_open("PROD/INVOICES(2005)");

 

 

/* Opens a program or a data queue */

$program = i5_open("*PGM/DEMOPGM");

$dataqueue = i5_open("*DTAQ/DEMODATA");

 

 

/* Opens two files on two AS400 */

 

$conn1 = i5_connect("FIRST_AS", "USER1", "PASSWORD1");

$conn2 = i5_connect("SECOND_AS", "USER2", "PASSWORD2");

 

if ($conn1 && $conn2) {

    $file_client1 = i5_open("PROD/CLIENTS", $conn1);

    $file_client2 = i5_open("PROD/CLIENTS", $conn2);

    }

 

 

See also

i5_free_file