Choose your database:
AnySQL
MySQL
MS SQL Server
PostgreSQL
SQLite
Firebird
Oracle
SQL Anywhere
DB2
MaxDB

Subscribe to our news:
Partners

DB2 PHP Generator online Help

Prev Return to chapter overview Next

Session methods

The following methods can be used to handle session variables.

 

Signature

Description

IsSessionVariableSet($name)

Checks if the given variable exists in the session.

GetSessionVariable($name)

Returns the value of the given session variable.

SetSessionVariable($name, $value)

Sets a value to a session variable.

UnSetSessionVariable($name)

Removes the given variable from the session.

 

The code in the examples below is used in the OnPreparePage event handler:

 

Example 1:

The following code is used to filter countries by life expectancy:

 

// default values

$minLifeExpectancy = 40;

$maxLifeExpectancy = 90;

 

// checking values in the browser address line 

if (GetApplication()->isGetValueSet('minLifeExpectancy') &&

       GetApplication()->isGetValueSet('maxLifeExpectancy')) {

    $minLifeExpectancy = GetApplication()->GetGETValue('minLifeExpectancy');

    $maxLifeExpectancy = GetApplication()->GetGETValue('maxLifeExpectancy');

 

}  // or (if not found) in the session

elseif (GetApplication()->IsSessionVariableSet('minLifeExpectancy') && 

          GetApplication()->IsSessionVariableSet('maxLifeExpectancy')) {

    $minLifeExpectancy = GetApplication()->GetSessionVariable('minLifeExpectancy');

    $maxLifeExpectancy = GetApplication()->GetSessionVariable('maxLifeExpectancy');

}

 

// applying filter to the dataset

$this->dataset->AddCustomCondition(

    "life_expectancy >= {$minLifeExpectancy} ".

    "AND life_expectancy <= {$maxLifeExpectancy}");

 

// saving calculated values to the session

GetApplication()->SetSessionVariable('minLifeExpectancy', $minLifeExpectancy);

GetApplication()->SetSessionVariable('maxLifeExpectancy', $maxLifeExpectancy);

 

Example 2:

The code below removes the 'minLifeExpectancy' and 'maxLifeExpectancy' variables from the session if the 'resetLifeExpectancyFilter' variable is specified in $_GET.

 

if (GetApplication()->IsGetValueSet('resetLifeExpectancyFilter')) {

  GetApplication()->UnSetSessionVariable('minLifeExpectancy');

  GetApplication()->UnSetSessionVariable('maxLifeExpectancy');

}

 



Prev Return to chapter overview Next