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. Special keyword I5_SAME_JOB can be used when running
PHP on IBM i. 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 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_SSO |
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.
|
|
I5_OPTIONS_JOBNAME |
Set the name of the new job in EASYCOM subsystem. |
|
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. |
|
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. |
|
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. 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 |
|
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_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 recommended to configure EASYCOM subsystem with PRESTART JOBS for a quick connection 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
opened 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 below.
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 below.
CCSID & Character encoding table:
All character encodings are not supported by PASE or Linux.
CCSID |
Character Encoding |
1046 |
IBM-1046 |
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",$conProperty) or 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