602SQL Documentation Index  



resource wb_connect( string server [, string application [, string user [, string password] [, error_info] ] ] )


Name of the server you are connecting to. Mandatory parameter.
Name of the application you will be working with. If not set, no application will be used.
Name of the user you are connecting as. If not set or empty, you will be connected as Anonymous.
Password of the specified user. If not set, an empty password will be used.
Output parameter; in case of failure, it contains error information


The function connects to the 602SQL server of the specified name and logs in as the selected user. If the application name is set, this application will be opened, all SQL statements will then be executed in this application context.

The connection is sustained until all access to it from the PHP application is lost (roughly until there is still the result of this function stored in some variable, or until there is still some open cursor on this connection), or until it is explicitly closed by the wb_close function. The connection is also terminated when the PHP script is done.

The maximum number of currently opened connections must be lower or equal to the wb_max_links parameter in PHP.INI. If this parameter equals -1, the connection count is not limited.

The default value of the wb_max_links parameter is -1.

Persistent database connections are created with the wb_pconnect function.

After function execution, the error_info output variable will be of array type and it will contain two elements:

1. error_info['wb_connect'] of the int type

It will contain one of the constants WB_CONNECT_ERROR_xxx (see the list bellow; the constants are defined in the PHP module, so it is possible to use their symbolic names in PHP) that will inform in which phase of wb_connect(), or wb_pconnect() function execution the error occurred. If no error occurred, it will contain WB_CONNECT_ERROR_OK value.

2. error_info['server'] of the int type

It will contain error number as reported by the 602SQL server, or it will contain zero (if the 602SQL server did not report - for given error - any other error). The list of constants explicitly defines when this entry will not be equal to zero.

List of WB_CONNECT_ERROR_xxx constants:
WB_CONNECT_ERROR_OK0 connection succeeded
WB_CONNECT_ERROR_NO_MEMORY1 memory allocation failed due to some data structure
WB_CONNECT_ERROR_CONNECT2 602SQL API function cd_connect() terminated with error (i.e. connection to the SQL server failed), the error_info['server'] contains the result of cd_connect function, i.e. one of the KSE_xxx constants
WB_CONNECT_ERROR_TOO_MANY_CONNECTIONS4 number of open connections to 602SQL databases is greater than the wb_max_links entry from the PHP.INI file
WB_CONNECT_ERROR_GET_SERVER_VERSION6 when attempting to determine SQL server version number, an error occurred; error_info['server'] contains the 602SQL error number
WB_CONNECT_ERROR_GET_SYSTEM_CHARSET7 when attempting to determine database system coding, an error occurred; error_info['server'] contains the 602SQL error number
WB_CONNECT_ERROR_LOGIN8 login to database failed (cd_Login() function failed with error), error_info['server'] contains the 602SQL error number
WB_CONNECT_ERROR_SET_PROGRESS_REPORT_MODULUS9 calling of the Set_progress_report_modulus() function failed with error; error_info['server'] contains the 602SQL error number
WB_CONNECT_ERROR_SET_APPLICATION10 an error in application setting; error_info['server'] contains the 602SQL error number
WB_CONNECT_ERROR_STORE_CONNECTION_RESOURCE11 error in entering the PHP resource with connection to database into the PHP variable list
WB_CONNECT_ERROR_RESOURCE_NOT_FOUND12 faintly probable error; it can occur when the PHP module finds in the PHP variable list a resource with connection to the SQL server that matches the specified parameters (it is connected to required database, with required user name and password and it has selected required application) but this resource is not of the type "connection to the 602SQL server"


Returns the identifier of the opened connection, if the operation is successful, otherwise it is FALSE. The return value (if successful) can be used as a parameter for the wb_exec function


Connect and display the user name

 $dsn = "sql_test";
 $appl = "testapl";
 $dbuser = "testuser";
 $passw  = "xxxx";
 $error_info = null; // out variable must be declared
 $conn = wb_connect($dsn, $appl, $dbuser, $passw, $error_info);
 if ($conn) {
   $res=wb_exec($conn,"SET :>temp = Who_am_I");
   if ($res) 
     echo("Connected as: ".$temp) ;  
  else {
   if ($error_info["wb_connect"]==WB_CONNECT_ERROR_LOGIN and ($error_info['server']==149 or $error_info['server']== 142 ))
   { echo ("Invalid login!!"); } 
   else { echo ("wb_connect error / 602sql error: ".$error_info["wb_connect"]." / ".$error_info['server']); }