PreviousNext
Help > API Functions > Connection > i5_private_connect
i5_private_connect

 

Create or get a private persistent connection to an AS/400 server.

This function acts like i5_pconnect with I5_OPTIONS_PRIVATE_CONNECTION option,
except that the connection ID is automatically managed by the function.

 

 resource i5_private_connect (string server, string user, string password [, array options] )

 

 

Parameters

server

Name of the IBM i server.
Can be either a DNS name, an IP address, or special keyword I5_SAME_JOB.

Special keyword I5_SAME_JOB can be used when running PHP on IBM i.
Connection is then established within the actual PHP server job.
No additional job is created on the system.

When running PHP on IBM i, set this parameter to an empty string to connect to the local system.

When running PHP on Windows or Linux, server name or address is mandatory. Default port is 6077.

 

To change port, add the port number after the server’s name or address, separated by a colon:

Example: I5SERVER:6079

user 

Username to use for connection.
When your PHP server is running on Windows or Linux, User name is mandatory.
When running PHP on IBM i, you can set this parameter to an empty string, to use the default user configured in PHP.

When option I5_OPTIONS_SSO is set, user and password parameters are not used.

 

password 

Password for the username.

options

Connection options in an associative array.

See below details about connection options.

 

Option

Description

 

I5_OPTIONS_JOBNAME

Set the name of the new job in EASYCOM subsystem.
Default is local machine name (The web server).

 

I5_OPTIONS_SQLNAMING

Set the naming convention in SQL. Statement to separate library and file names.

"SYS" (default) to use slashes (/).

"SQL" to use dots (.).

 

I5_OPTIONS_DECIMALPOINT

Set the character value to use as decimal point.
Default is point (.).

 

I5_OPTIONS_LOCALCP

Set the local code page used by PHP application.

See comments bellow about Character Set & Code page.

 

I5_OPTIONS_CODEPAGEFILE

Change the character conversion rules by using an external conversion table.

 

I5_OPTIONS_RMTCCSID

Set the EBCDIC CCSID to use for data conversion.

If Easycom client job on the i5 doesn’t have a CCSID, and if its default CCSID is not appropriated, the application can choose the right EBCDIC CCSID.

 

I5_OPTIONS_EACUNLOCK

Password to unlock EASYCOM server, by calling EACP003 exit program.

 

I5_OPTIONS_ALIAS

Alias name given to the connection. This option has an effect only on when PHP server is running on Windows, in multi thread configuration.
If a connection having same username, password and alias is already active, it is reused.

 

I5_OPTIONS_INITLIBL

specifies library names to add on top of library list.

 

I5_OPTIONS_IDLE_TIMEOUT

Used on i5_pconnect() only.

Set the delay (seconds) after what a persistent connection is closed if it not reused by a script.

Default is infinite.

 

I5_OPTIONS_PRIVATE_CONNECTION

Used on i5_pconnect() only.

Set the ID of the persistent connection to reuse.

 

I5_OPTIONS_AUTOMATIC_NEXT_RESULT

String value.
If this option is not set to "1", you will have to call i5_next_result() before to fetch from the first result set resulting from a CALL SQL statement.

For compatibility with previous Easycom versions, the first i5_fetch_xxx() fetches the parameters values, if this option is not set to "1".

 

I5_OPTIONS_SSL_MODE

Windows and Linux only!

I5_OPTIONS_SSL_TRUE/ I5_OPTIONS_SSL_FALSE/ I5_OPTIONS_SSL_MANDATORY

Forces SSL mode.

If true, the SSL connection will be attempted, and if SSL cannot be used, a non-secure connection will be attempted.

If mandatory, SSL connection will be attempted, and if SSL cannot be used, connection is aborted.

 

I5_OPTIONS_SSL_INTF

I5_SSL_INTERFACE_WINDOWS / I5_SSL_INTERFACE_OPENSSL
SSL interface to use.

 

I5_OPTIONS_SSL_CAFILE

In OpenSSL, the CA file to verify server certificate.

 

I5_OPTIONS_SSL_USER_CERT_FILE

In OpenSSL, the CA path in which searching for authority certificates. This is to verify the server certificate.

 

I5_OPTIONS_SSL_USER_CERT_FILE

Client certificate file. This is for client certificate authentication when OpenSSL is used. The certificate file must be in PEM format. When using Windows interface, the option is not needed: the certificate is automatically selected.

 

I5_OPTIONS_SSL_USER_CERT_PKEY_FILE

Client certificate private key file. This is the file path for the OpenSSL private key file. When using Windows interface, the option is not needed: the certificate and private key is automatically selected.

 

I5_OPTIONS_SSL_USER_CERT_PASSPHRASE

Passphrase to be able to read the private key file. This is used in OpenSSL only.

 

 

Return

AS/400 connection resource or false on failure.

The connection resource will be given on input to subsequent function calls.

If only one connection is open by the script, the connection resource is optional on subsequent function calls.

 

Error returned

I5_ERR_MEMALLOC

3

Not enough memory

I5_ERR_PHP_OPTIONSTYPE

259

The type of " I5_OPTIONS_ALIAS" option must

be x and not x

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

I5_ERR_PHP_PRIVATE_CONNECTION_NOT_FOUND

285

the -1 connection has not been found.

 

I5_ERR_PHP_LOCALHOST_NOT_PERMIT

286

you must specify the AS/400 address

 

 

Details

 

This function acts like i5_connect(), except for the following differences :

- If a connection to the same AS/400 server, same user profile and password, already exists within the current PHP session, it will be reused.

- If such a connection doesn’t exist, a new one is created, kept open when the PHP script ends, and dedicated to the current PHP session.

- A subsequent call to i5_close() will not close the connection.
Use i5_pclose() to definitely close the connection.

- A time out can be set with option I5_OPTIONS_IDLE_TIMEOUT.
If the connection isn’t reused during that delay, it will be automatically closed.

- Easycom manages session affinity by creating private jobs for the PHP session. All the PHP scripts inside the same PHP session, use the same AS/400 job along the session.

 

Call function i5_get_property(), with option I5_NEW_CONNECTION , to know if the returned connection is a new one, or not.

 

Note:

When a PHP script connect to a private i5 job, it gets a connection that will not be reused by any other PHP session.
The job environment is maintained along the PHP session. For example, If a script creates a file in QTEMP library, this file will be present for subsequent scripts in the same session.
Resources and cursors are not maintained !

 

I5_private_connect() uses same option as i5_pconnect().
Following special options apply only to i5_pconnect() and i5_private_connect().

 

I5_OPTIONS_IDLE_TIMEOUT:

Set the maximum delay (in seconds) the AS/400 job will remain active without any request from PHP.
Default delay is 900 seconds.
If the PHP session ends without running i5_pclose(), the job will end after this delay.

 

I5_OPTIONS_PRIVATE_CONNECTION:

Setting value 0 to this option will force Easycom to create a new private connection, even if one already exist.

 

Example

 

Example 1: Connecting to a private job.

 

 

    $option = array();

    // I5_OPTIONS_IDLE_TIMEOUT After a delay with no activity, the job will end.

    $option[I5_OPTIONS_IDLE_TIMEOUT] =  "50";

 

    $retcon = i5_private_connect($connect$user$pass$option);

    if (is_bool($retcon) && $retcon == FALSE){

        $errorTab = i5_error();

        print_r($errorTab);

    } else {

        $isnew = i5_get_property(I5_NEW_CONNECTION$retcon);

        if ($isnew) {

           /*  New connection. Do some job initialization */;

        } else {

           /*  Connection was already existing. Using the same job */;

        }

    }

    

 

See also

 

i5_close

i5_pclose

i5_get_property

i5_set_property

i5_pconnect