OCI8Connection Class Reference

Inheritance diagram for OCI8Connection:

ConnectionCommon Connection

List of all members.

Public Member Functions

 connect ($dsninfo, $flags=0)
 Connect to a database and log in as the specified user.
 close ()
 executeQuery ($sql, $fetchmode=null)
 executeUpdate ($sql)
 getUpdateCount ()
 Gets the number of rows affected by the data manipulation query.
 applyLimit (&$sql, $offset, $limit)
 Build Oracle-style query with limit or offset.
 nativeError ($result=null)
 Get the native Oracle Error Message as a string.
 getDatabaseInfo ()
 getIdGenerator ()
 prepareStatement ($sql)
 Oracle supports native prepared statements, but the oci_parse call is actually called by the OCI8PreparedStatement class because some additional SQL processing may be necessary ( e.g.
 prepareCall ($sql)
 createStatement ()

Protected Member Functions

 beginTrans ()
 Start a database transaction.
 commitTrans ()
 Commit the current transaction.
 rollbackTrans ()
 Roll back ( undo ) the current transaction.

Protected Attributes

 $lastStmt = null
 $execMode = OCI_COMMIT_ON_SUCCESS


Detailed Description

Definition at line 37 of file OCI8Connection.php.


Member Function Documentation

OCI8Connection::applyLimit ( &$  sql,
offset,
limit 
)

Build Oracle-style query with limit or offset.

If the original SQL is in variable: query then the requlting SQL looks like this:

 SELECT B.* FROM ( 
          SELECT A.*, rownum as TORQUE$ROWNUM FROM ( 
                  query
           ) A
      ) B WHERE B.TORQUE$ROWNUM > offset AND B.TORQUE$ROWNUM
     <= offset + limit
 

Parameters:
string &$sql the query
int $offset
int $limit
Returns:
void ( $sql parameter is currently manipulated directly )

Implements Connection.

Definition at line 293 of file OCI8Connection.php.

00294    {
00295         $sql          =
00296       'SELECT B.* FROM (  '
00297       .  'SELECT A.*, rownum AS CREOLE$ROWNUM FROM (  '
00298       . $sql
00299       . '  ) A '
00300       .  ' ) B WHERE ';
00301 
00302         if ( $offset > 0 )
00303     {
00304             $sql        .= ' B.CREOLE$ROWNUM > ' . $offset;            
00305 
00306             if ( $limit > 0 )
00307       {
00308                 $sql      .= ' AND B.CREOLE$ROWNUM <= '
00309                   . ( $offset + $limit );
00310             }
00311         }
00312 
00313     else
00314     {
00315       $sql        .= ' B.CREOLE$ROWNUM <= ' . $limit;
00316     }
00317    } 

OCI8Connection::beginTrans (  )  [protected]

Start a database transaction.

Exceptions:
SQLException 
Returns:
void

Reimplemented from ConnectionCommon.

Definition at line 203 of file OCI8Connection.php.

00204     {
00205         $this->execMode     = OCI_DEFAULT;
00206     }

OCI8Connection::close (  ) 

See also:
Connection::disconnect()

Implements Connection.

Definition at line 126 of file OCI8Connection.php.

00127     {
00128         $ret = @oci_close( $this->dblink );
00129         $this->dblink = null;
00130         return $ret;
00131     }        

OCI8Connection::commitTrans (  )  [protected]

Commit the current transaction.

Exceptions:
SQLException 
Returns:
void

Reimplemented from ConnectionCommon.

Definition at line 213 of file OCI8Connection.php.

References $result, and nativeError().

00214     {
00215         $result         = oci_commit( $this->dblink );
00216 
00217         if ( ! $result )
00218     {
00219             throw new SQLException( 'Unable to commit transaction'
00220         , $this->nativeError()
00221       );
00222         }
00223 
00224         $this->execMode     = OCI_COMMIT_ON_SUCCESS;
00225     }

OCI8Connection::connect ( dsninfo,
flags = 0 
)

Connect to a database and log in as the specified user.

Parameters:
array $dsn The data source hash.
int $flags Any connection flags. public
Exceptions:
SQLException 
Returns:
void

Implements Connection.

Definition at line 56 of file OCI8Connection.php.

References ConnectionCommon::$flags, executeQuery(), and Creole::PERSISTENT.

00057     {
00058         if ( !extension_loaded( 'oci8' ) )
00059     {
00060             throw new SQLException( 'oci8 extension not loaded' );
00061         }
00062 
00063         $this->dsn        = $dsninfo;
00064         $this->flags      = $flags;
00065         
00066         $persistent       =
00067       ( $flags & Creole::PERSISTENT === Creole::PERSISTENT );
00068         
00069         $user         = $dsninfo[ 'username' ];
00070         $pw           = $dsninfo[ 'password' ];
00071         $hostspec       = $dsninfo[ 'hostspec' ];
00072         $db         = $dsninfo[ 'database' ];
00073 
00074         $connect_function   = ( $persistent )
00075                   ? 'oci_pconnect'
00076                   : 'oci_connect';
00077     
00078     $encoding = !empty($dsninfo['encoding']) ? $dsninfo['encoding'] : null;
00079     
00080     @ini_set( 'track_errors', true );
00081 
00082         if ( $db && $hostspec && $user && $pw )
00083   {
00084       $conn       = @$connect_function( $user, $pw, "//$hostspec/$db", $encoding);
00085   }
00086         elseif ( $hostspec && $user && $pw )
00087     {
00088       $conn       = @$connect_function( $user, $pw, $hostspec, $encoding );
00089         }
00090     
00091     elseif ( $user || $pw )
00092     {
00093       $conn       = @$connect_function( $user, $pw, null, $encoding );
00094         }
00095     
00096     else
00097     {
00098       $conn       = false;
00099         }
00100 
00101         @ini_restore( 'track_errors' );
00102         
00103         if ( $conn == false )
00104     {
00105             $error        = oci_error();
00106             $error        = ( is_array( $error ) )
00107                   ? $error[ 'message' ]
00108                   : null;
00109 
00110             throw new SQLException( 'connect failed', $error );
00111         }
00112 
00113         $this->dblink     = $conn;
00114 
00115         //connected ok, need to set a few environment settings
00116         //please note, if this is changed, the function setTimestamp and setDate in OCI8PreparedStatement.php
00117         //must be changed to match
00118         $sql = "ALTER SESSION SET NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'";
00119         $this->executeQuery($sql);
00120     }

OCI8Connection::createStatement (  ) 

See also:
Connection::createStatement()

Implements Connection.

Definition at line 387 of file OCI8Connection.php.

00388     {
00389         require_once 'creole/drivers/oracle/OCI8Statement.php';
00390 
00391         return new OCI8Statement( $this );
00392     }

OCI8Connection::executeQuery ( sql,
fetchmode = null 
)

See also:
Connection::executeQuery()

Implements Connection.

Definition at line 136 of file OCI8Connection.php.

References $result, and nativeError().

Referenced by connect().

00137     {
00138         $this->lastQuery    = $sql;
00139 
00140         // $result = @oci_parse( $this->dblink, $sql );
00141         $result         = oci_parse( $this->dblink, $sql );
00142 
00143         if ( ! $result )
00144     {
00145             throw new SQLException( 'Unable to prepare query'
00146         , $this->nativeError()
00147         , $sql
00148       );
00149         }
00150 
00151         $success        = oci_execute( $result, $this->execMode );
00152 
00153         if ( ! $success )
00154     {
00155             throw new SQLException( 'Unable to execute query'
00156         , $this->nativeError( $result )
00157         , $sql
00158       );
00159         }
00160         
00161         return new OCI8ResultSet( $this, $result, $fetchmode );
00162     }

OCI8Connection::executeUpdate ( sql  ) 

See also:
Connection::simpleUpdate()

Implements Connection.

Definition at line 169 of file OCI8Connection.php.

References nativeError().

00170     {    
00171         $this->lastQuery    = $sql;
00172 
00173         $statement        = oci_parse( $this->dblink, $sql );
00174     
00175         if ( ! $statement )
00176     {
00177             throw new SQLException( 'Unable to prepare update'
00178         , $this->nativeError()
00179         , $sql
00180       );
00181         }
00182                 
00183         $success        = oci_execute( $statement, $this->execMode );
00184 
00185         if ( ! $success )
00186     {
00187             throw new SQLException( 'Unable to execute update'
00188         , $this->nativeError( $statement )
00189         , $sql
00190       );
00191         }
00192 
00193         $this->lastStmt     = $statement;
00194 
00195         return oci_num_rows( $statement );
00196     }

OCI8Connection::getDatabaseInfo (  ) 

See also:
Connection::getDatabaseInfo()

Implements Connection.

Definition at line 344 of file OCI8Connection.php.

00345     {
00346         require_once 'creole/drivers/oracle/metadata/OCI8DatabaseInfo.php';
00347 
00348         return new OCI8DatabaseInfo( $this );
00349     }

OCI8Connection::getIdGenerator (  ) 

See also:
Connection::getIdGenerator()

Implements Connection.

Definition at line 354 of file OCI8Connection.php.

00355     {
00356         require_once 'creole/drivers/oracle/OCI8IdGenerator.php';
00357 
00358         return new OCI8IdGenerator( $this );
00359     }

OCI8Connection::getUpdateCount (  ) 

Gets the number of rows affected by the data manipulation query.

Returns:
int Number of rows affected by the last query.
Todo:
-cOCI8Connection Figure out whether getUpdateCount() should throw exception on error or just return 0.

Implements Connection.

Definition at line 255 of file OCI8Connection.php.

References $result, and nativeError().

00256     {
00257         if ( ! $this->lastStmt )
00258     {
00259             return 0;
00260         }
00261 
00262         $result         = oci_num_rows( $this->lastStmt );
00263 
00264         if ( $result === false )
00265     {
00266             throw new SQLException( 'Update count failed'
00267         , $this->nativeError( $this->lastStmt )
00268       );
00269         }
00270 
00271         return $result;
00272     }

OCI8Connection::nativeError ( result = null  ) 

Get the native Oracle Error Message as a string.

Parameters:
string $msg The Internal Error Message
mixed $errno The Oracle Error resource

Definition at line 325 of file OCI8Connection.php.

References $result.

Referenced by commitTrans(), executeQuery(), executeUpdate(), getUpdateCount(), and rollbackTrans().

00326   {
00327     if ( $result !== null )
00328     {
00329       $error        = oci_error( $result );
00330     }
00331   
00332     else
00333     {
00334       $error        = oci_error( $this->dblink );
00335     }         
00336 
00337     return $error[ 'code' ] . ': ' . $error[ 'message' ];
00338   }

OCI8Connection::prepareCall ( sql  ) 

See also:
Connection::prepareCall()

Reimplemented from ConnectionCommon.

Definition at line 379 of file OCI8Connection.php.

00380   {
00381         throw new SQLException( 'Oracle driver does not yet support stored procedures using CallableStatement.' );
00382     }

OCI8Connection::prepareStatement ( sql  ) 

Oracle supports native prepared statements, but the oci_parse call is actually called by the OCI8PreparedStatement class because some additional SQL processing may be necessary ( e.g.

to apply limit ).

See also:
OCI8PreparedStatement::executeQuery()

OCI8PreparedStatement::executeUpdate()

Connection::prepareStatement()

Implements Connection.

Definition at line 369 of file OCI8Connection.php.

00370     {
00371         require_once 'creole/drivers/oracle/OCI8PreparedStatement.php';
00372 
00373         return new OCI8PreparedStatement( $this, $sql );
00374     }

OCI8Connection::rollbackTrans (  )  [protected]

Roll back ( undo ) the current transaction.

Exceptions:
SQLException 
Returns:
void

Reimplemented from ConnectionCommon.

Definition at line 233 of file OCI8Connection.php.

References $result, and nativeError().

00234     {
00235         $result         = oci_rollback( $this->dblink );
00236 
00237         if ( ! $result )
00238     {
00239             throw new SQLException( 'Unable to rollback transaction'
00240         , $this->nativeError()
00241       );
00242         }
00243 
00244         $this->execMode     = OCI_COMMIT_ON_SUCCESS;
00245     }


Member Data Documentation

OCI8Connection::$execMode = OCI_COMMIT_ON_SUCCESS [protected]

Definition at line 45 of file OCI8Connection.php.

OCI8Connection::$lastStmt = null [protected]

Definition at line 39 of file OCI8Connection.php.


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

Generated on Wed May 6 23:10:50 2009 for fareofficelib by  doxygen 1.5.8