i5_connect

 

Open a new connection to the IBM i - AS/400 server.

 

resource i5_connect (

string server, string user,
string password [, array options] )

 

Parameters

 

server

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

New ! 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 cretated on the system.
This option is not available with the i5-Toolkit free version.

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. This default port connects to the default standalone Easycom server, running in EASYCOM subsystem on the targer system.

For Zend Server or Zend Core, default port is 6079. This value is configured un php.ini file, section [zend], entry "i5comm.Port=6079". It connects to the Easycom server running in Zend subsystem.

To change port to connect to, add the port number at the end the server name or address, separated by a colon:
Exemple: I5SERVER:6079

 

user 

User name 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 user name.

 

options

Connection options in an associative array.

See below details about connection options.

 

Option

Description

 

I5_OPTIONS_SSO

New ! Single Sign On. Connection is established using the user id signed on the end user station. Kerberos and EIM are used by Easycom to process identification.

This option can only be used with PHP on IBM i.

This option is not available with the free version of i5-Toolkit.

 

 

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 attempred.

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 cerficicate.

 

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.

 

Returns:

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_LOCALHOST_NOT_PERMIT

286

you must specify the AS/400 address

 

 

Details

Open a connection with specified AS400 server (name or IP address) for a given user profile and password.

This function must be called first, before any subsequent function is called.
A new job is created in EASYCOM subsystem, except when I5_SAME_JOB is set for server parameter.

The connection will be closed at the end of the script, except when running PHP server on Windows, with a multi threaded web server.
To keep the connection open at the end of the script, use i5_pconnect(), or i5_private_connect()

Note: It is recommend to configure EASYCOM subsystem with PRESTART JOBS for a quick connections opening.

Note: Running Easycom For PHP on Windows, in multi thread configuration.

In a multi thread environment, the PHP application can follow up the web session.

Connections can be kept open within the web session, with files and queries.
So, Easycom connections are not automatically closed at the end of each script.

This feature is available only on Windows PHP servers.

 

Character Set & Code page - I5_OPTIONS_LOCALC, I5_OPTIONS_RMTCCSID :

 

I5_OPTONS_LOCALCP option sets the local code page to use on the PHP server.
This is an ASCII character set. All EBCDIC i5 data will be converted to and from this code page.

If local code page to use is not UTF-8, option is set to a single CCSID value, or a character encoding.

Example:

I5_OPTIONS_LOCALCP=>"ISO8859-8"

I5_OPTIONS_LOCALCP=>"916"

In this case, any ASCII CCSID can be used.

Only character encoding supported by PASE or Linux can be used. See CCSID & character encoding table bellow.

 

If local code page is UTF-8, option contains an intermediate code page, prefixed by "UTF-8;"

Example:

 I5_OPTIONS_LOCALCP=>"UTF-8;ISO8859-1"

Easycom will convert to and from UTF-8 in two steps.

UTF-8 ß à Intermediate code page ß à EBCDIC

In this case, the CCSID or character encoding given for the intermediate code page must be present in the table bellow.

CCSID & Character encoding table :

ALL character encoding are not supported by PASE or Linux.

CCSID

Character Encoding

1046
1124
1126
1252
850
856
921
922
932
943
819
912
913
914
915
1089
813
916
920
923

IBM-1046
IBM-1124
IBM-1129
IBM-1252
IBM-850
IBM-856
IBM-921
IBM-922
IBM-932
IBM-943
ISO8859-1
ISO8859-2
ISO8859-3
ISO8859-4
ISO8859-5
ISO8859-6
ISO8859-7
SO8859-8
ISO8859-9
ISO8859-15

 

Example

 

 

/* Basic connection to AS400 */

$conn = i5_connect("193.104.118.120""QPGMR""PASSW"or die(i5_errormsg());

echo " Connection OK <BR>";

 

 

/* Connection to AS400 setting options */

$conProperty = array(I5_OPTIONS_JOBNAME=>"PHPJOB"I5_OPTIONS_INITLIBL=>"WEBLIB");

$conn = i5_connect("MYAS400""QPGMR""PASSW",$conPropertyor die(i5_errormsg());

echo " Connection OK <BR>";

 

 

/* Connection error detail in case of failure */

$conn = i5_connect("193.104.118.120""QPGMR""PASSW");

if (!$conn) {

    $error = i5_error();

    echo " Error during connection\n";

    echo "<BR> Error number: ".$error["num"];

    echo "<BR> Error category: ".$error["cat"];

    echo "<BR> Error message: ".$error["msg"];

    echo "<BR> Error description: ".$error["desc"];

    trigger_error("I5 connection fails", E_USER_ERROR);

else {

    echo " Connection OK ";

}

 

 

/* Disconnect from AS/400 */

$ret = i5_close($conn);

If ($ret){

    echo " I5 disconnected ";

else {

    $ret = i5_errormsg($conn);

}

 

/* SSL connection with user certificate and OpenSSL interface */

$option = array();

$option[I5_OPTIONS_JOBNAME] = "PHP_JOB";

$option[I5_OPTIONS_SSL_MODE] = I5_OPTIONS_SSL_TRUE;

$option[I5_OPTIONS_SSL_INTF] = I5_SSL_INTERFACE_OPENSSL;

$option[I5_OPTIONS_SSL_CAFILE] = 'C:\Temp\OpenSSL\P520CA.crt';

$option[I5_OPTIONS_SSL_USER_CERT_FILE] = 'C:\Temp\OpenSSL\qpgmr.pem';

$option[I5_OPTIONS_SSL_USER_CERT_PKEY_FILE] = 'C:\Temp\OpenSSL\qpgmr_p.key';

$option[I5_OPTIONS_SSL_USER_CERT_PASSPHRASE] = 'PASSW_PRIVATE';

$conn = i5_connect("193.104.118.120""QPGMR""PASSW"$option);

if (!$conn) {

        $error = i5_error();

        echo " Error during connection\n";

        echo "<BR> Error number: ".$error["num"];

        echo "<BR> Error category: ".$error["cat"];

        echo "<BR> Error message: ".$error["msg"];

        echo "<BR> Error description: ".$error["desc"];

        trigger_error("I5 connection fails", E_USER_ERROR);

else {

        echo " Connection OK ";

}

 

 

 

See also

 

i5_pconnect
i5_private_connect
i5_close

i5_adopt_authority