Public Member Functions

db2Sequence Class Reference

Public Member Functions

 __construct ($sequence, $max, $connection)
 Constructor.
 getSequence ()
 Return int value for named sequence.
 setSequence ()
 Create sequence.

Detailed Description

Definition at line 15 of file db2Sequence.php.


Constructor & Destructor Documentation

__construct ( sequence,
max,
connection 
)

Constructor.

public

Parameters:
str $sequence
int $max
mixed $connection

Definition at line 57 of file db2Sequence.php.

    {
        $this->objConnection = $connection;
        $this->objMax        = $max;
        $this->objSequence   = $sequence;
    }


Member Function Documentation

getSequence (  ) 

Return int value for named sequence.

public

Returns:
int

Definition at line 70 of file db2Sequence.php.

    {
        $objStmt = db2_exec( $this->objConnection, 'SELECT NEXTVAL FOR ' . $this->objSequence . ' FROM SYSIBM.SYSDUMMY1' )
        or trigger_error( db2_stmt_errormsg(), E_USER_WARNING );

        $objResult = db2_fetch_array( $objStmt );
        return $objResult[0];
    }

setSequence (  ) 

Create sequence.

public

Returns:
mixed

Definition at line 85 of file db2Sequence.php.

    {
        //make sure $this->objMax is an unsigned int > 0
        $objMax   = ( is_numeric( $this->objMax ) && $this->objMax > 0 ) ? ' MAXVALUE ' . ( int )$this->objMax : '';
        $objQuery = 'CREATE SEQUENCE ' . $this->objSequence . ' INCREMENT BY 1 START WITH 1 MINVALUE 1' . $objMax . ' NO CACHE';

        return db2_exec( $this->objConnection, $objQuery )
        or trigger_error( db2_stmt_errormsg(), E_USER_WARNING );
    }


The documentation for this class was generated from the following file: