ConnectionCommon Class Reference

Inheritance diagram for ConnectionCommon:

MSSQLConnection MySQLConnection MySQLiConnection OCI8Connection ODBCConnection PgSQLConnection SQLiteConnection

List of all members.

Public Member Functions

 __sleep ()
 This "magic" method is invoked upon serialize() and works in tandem with the __wakeup() method to ensure that your database connection is serializable.
 __wakeup ()
 This "magic" method is invoked upon unserialize().
 getResource ()
 getDSN ()
 getFlags ()
 prepareCall ($sql)
 Creates a CallableStatement object for calling database stored procedures.
 supportsNestedTrans ()
 Driver classes should override this if they support transactions.
 begin ()
 Begins a transaction (if supported).
 commit ()
 Commits statements in a transaction.
 rollback ()
 Rollback changes in a transaction.
 setAutoCommit ($bit)
 Enable/disable automatic commits.
 getAutoCommit ()
 Get auto-commit status.
 isConnected ()
 Returns false if connection is closed.

Protected Member Functions

 beginTrans ()
 Begin new transaction.
 commitTrans ()
 Commit the current transaction.
 rollbackTrans ()
 Roll back (undo) the current transaction.

Protected Attributes

 $transactionOpcount = 0
 $dblink
 $dsn
 $flags = 0


Detailed Description

Definition at line 32 of file ConnectionCommon.php.


Member Function Documentation

ConnectionCommon::__sleep (  ) 

This "magic" method is invoked upon serialize() and works in tandem with the __wakeup() method to ensure that your database connection is serializable.

This method returns an array containing the names of any members of your class which need to be serialized in order to allow the class to re-connect to the database when it is unserialized.

Developers:

Note that you cannot serialize resources (connection links) and expect them to be valid when you unserialize. For this reason, you must re-connect to the database in the __wakeup() method.

It's up to your class implimentation to ensure that the necessary data is serialized. You probably at least need to serialize:

(1) the DSN array used by connect() method (2) Any flags that were passed to the connection (3) Possibly the autocommit state

Returns:
array The class variable names that should be serialized.
See also:
__wakeup()

DriverManager::getConnection()

DatabaseInfo::__sleep()

Definition at line 94 of file ConnectionCommon.php.

00095     {
00096         return array('dsn', 'flags');
00097     }

ConnectionCommon::__wakeup (  ) 

This "magic" method is invoked upon unserialize().

This method will re-connects to the database using the information that was stored using the __sleep() method.

See also:
__sleep()

Definition at line 105 of file ConnectionCommon.php.

00106     {
00107         $this->connect($this->dsn, $this->flags);
00108     }

ConnectionCommon::begin (  ) 

Begins a transaction (if supported).

Definition at line 157 of file ConnectionCommon.php.

References beginTrans(), and supportsNestedTrans().

Referenced by setAutoCommit().

00158     {
00159         if ($this->transactionOpcount === 0 || $this->supportsNestedTrans()) {
00160             $this->beginTrans();
00161         }
00162         $this->transactionOpcount++;
00163     }

ConnectionCommon::beginTrans (  )  [protected]

Begin new transaction.

Driver classes should override this method if they support transactions.

Reimplemented in MSSQLConnection, MySQLConnection, MySQLiConnection, ODBCConnection, OCI8Connection, PgSQLConnection, and SQLiteConnection.

Definition at line 230 of file ConnectionCommon.php.

Referenced by begin().

00231     {
00232     }

ConnectionCommon::commit (  ) 

Commits statements in a transaction.

Definition at line 168 of file ConnectionCommon.php.

References commitTrans(), and supportsNestedTrans().

Referenced by setAutoCommit().

00169     {
00170         if ($this->transactionOpcount > 0) {
00171             if ($this->transactionOpcount == 1 || $this->supportsNestedTrans()) {
00172                 $this->commitTrans();
00173             }
00174             $this->transactionOpcount--;       
00175         }
00176     }

ConnectionCommon::commitTrans (  )  [protected]

Commit the current transaction.

Driver classes should override this method if they support transactions.

Reimplemented in MSSQLConnection, MySQLConnection, MySQLiConnection, ODBCConnection, OCI8Connection, PgSQLConnection, and SQLiteConnection.

Definition at line 238 of file ConnectionCommon.php.

Referenced by commit().

00239     {
00240     }

ConnectionCommon::getAutoCommit (  ) 

Get auto-commit status.

Returns:
boolean

Definition at line 221 of file ConnectionCommon.php.

00222     {
00223         return ($this->transactionOpcount == 0);
00224     }

ConnectionCommon::getDSN (  ) 

See also:
Connection::getDSN()

Definition at line 121 of file ConnectionCommon.php.

00121                              {
00122         return $this->dsn;
00123     }

ConnectionCommon::getFlags (  ) 

See also:
Connection::getFlags()

Definition at line 128 of file ConnectionCommon.php.

00129     {
00130         return $this->flags;
00131     }    

ConnectionCommon::getResource (  ) 

See also:
Connection::getResource()

Definition at line 113 of file ConnectionCommon.php.

00114     {
00115         return $this->dblink;
00116     }

ConnectionCommon::isConnected (  ) 

Returns false if connection is closed.

Returns:
boolean

Definition at line 254 of file ConnectionCommon.php.

00255     {
00256         return !empty($this->dblink);
00257     }

ConnectionCommon::prepareCall ( sql  ) 

Creates a CallableStatement object for calling database stored procedures.

Parameters:
string $sql
Returns:
CallableStatement

Reimplemented in MSSQLConnection, MySQLConnection, MySQLiConnection, ODBCConnection, OCI8Connection, PgSQLConnection, and SQLiteConnection.

Definition at line 139 of file ConnectionCommon.php.

00140     {
00141         throw new SQLException("Current driver does not support stored procedures using CallableStatement.");
00142     }    

ConnectionCommon::rollback (  ) 

Rollback changes in a transaction.

Definition at line 181 of file ConnectionCommon.php.

References rollbackTrans(), and supportsNestedTrans().

00182     {
00183         if ($this->transactionOpcount > 0) {
00184             if ($this->transactionOpcount == 1 || $this->supportsNestedTrans()) {
00185                 $this->rollbackTrans();
00186             }
00187             $this->transactionOpcount--;       
00188         }
00189     }

ConnectionCommon::rollbackTrans (  )  [protected]

Roll back (undo) the current transaction.

Driver classes should override this method if they support transactions.

Reimplemented in MSSQLConnection, MySQLConnection, MySQLiConnection, ODBCConnection, OCI8Connection, PgSQLConnection, and SQLiteConnection.

Definition at line 246 of file ConnectionCommon.php.

Referenced by rollback().

00247     {
00248     }

ConnectionCommon::setAutoCommit ( bit  ) 

Enable/disable automatic commits.

Pushes SQLWarning onto $warnings stack if the autocommit value is being changed mid-transaction. This function is overridden by driver classes so that they can perform the necessary begin/end transaction SQL.

If auto-commit is being set to TRUE, then the current transaction will be committed immediately.

Parameters:
boolean $bit New value for auto commit.
Returns:
void

Definition at line 202 of file ConnectionCommon.php.

References begin(), and commit().

00203     {
00204         if ($this->transactionOpcount > 0) {
00205             trigger_error("Changing autocommit in mid-transaction; committing " . $this->transactionOpcount . " uncommitted statements.", E_USER_WARNING);
00206         }
00207 
00208         if (!$bit) {
00209             $this->begin();
00210         }
00211         else {
00212             $this->commit();
00213         }
00214     }

ConnectionCommon::supportsNestedTrans (  ) 

Driver classes should override this if they support transactions.

Returns:
boolean

Definition at line 149 of file ConnectionCommon.php.

Referenced by begin(), commit(), and rollback().

00150     {
00151         return false;
00152     }


Member Data Documentation

ConnectionCommon::$dblink [protected]

Definition at line 53 of file ConnectionCommon.php.

ConnectionCommon::$dsn [protected]

Definition at line 59 of file ConnectionCommon.php.

ConnectionCommon::$flags = 0 [protected]

ConnectionCommon::$transactionOpcount = 0 [protected]

Definition at line 47 of file ConnectionCommon.php.


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

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