class_DatabaseConnection.php

Go to the documentation of this file.
00001 <?php
00024 class DatabaseConnection extends BaseMiddleware implements DatabaseConnector, Registerable {
00028         private $connectData = array(
00029                 'login' => "",
00030                 'pass'  => "",
00031                 'dbase' => "",
00032                 'host'  => ""
00033         );
00034 
00035         // The real database layer
00036         private $dbLayer = null;
00037 
00038         // An instance of this class
00039         private static $thisInstance = null;
00040 
00046         protected function __construct() {
00047                 // Call parent constructor
00048                 parent::__construct(__CLASS__);
00049         }
00050 
00051         // Create new database connection layer
00052         public final static function createDatabaseConnection (DebugMiddleware $debugInstance, DatabaseFrontendInterface $dbLayer) {
00053                 // Get instance
00054                 $dbInstance = new DatabaseConnection();
00055 
00056                 // Set debug output handler
00057                 $dbInstance->setDebugInstance($debugInstance);
00058 
00059                 // Set database layer
00060                 $dbInstance->setDatabaseLayer($dbLayer);
00061 
00062                 // Set db instance
00063                 self::$thisInstance = $dbInstance;
00064 
00065                 // Return instance
00066                 return $dbInstance;
00067         }
00068 
00069         // Get an instance of this class
00070         public final static function getInstance () {
00071                 return self::$thisInstance;
00072         }
00073 
00074         // Public setter for database connection
00075         public final function setConnectionData ($login, $pass, $dbase, $host="localhost") {
00076                 // Transfer connection data
00077                 $this->connectData['login'] = (string) $login;
00078                 $this->connectData['pass']  = (string) $pass;
00079                 $this->connectData['dbase'] = (string) $dbase;
00080                 $this->connectData['host']  = (string) $host;
00081         }
00082 
00088         public final function getConnectionData () {
00089                 return $this->connectData;
00090         }
00091 
00097         public final function setDatabaseLayer (DatabaseFrontendInterface $dbLayer) {
00098                 $this->dbLayer = $dbLayer;
00099         }
00100 
00106         public final function getIndexKey () {
00107                 return $this->dbLayer->getIndexKey();
00108         }
00109 
00118         public function doSelectByTableCriteria ($tableName, Criteria $criteriaInstance) {
00119                 // Connect to the database
00120                 $this->dbLayer->connectToDatabase();
00121 
00122                 // Get result from query
00123                 $result = $this->dbLayer->querySelect("array", $tableName, $criteriaInstance);
00124 
00125                 // Return the result
00126                 return $result;
00127         }
00128 
00134         public final function getLastException () {
00135                 $exceptionInstance = $this->dbLayer->getLastException();
00136                 return $exceptionInstance;
00137         }
00138 
00145         public function queryInsertDataSet (StoreableCriteria $dataSetInstance) {
00146                 // Connect to the database
00147                 $this->dbLayer->connectToDatabase();
00148 
00149                 // Ask the database layer
00150                 $this->dbLayer->queryInsertDataSet($dataSetInstance);
00151         }
00152 
00159         public function queryUpdateDataSet (StoreableCriteria $dataSetInstance) {
00160                 // Connect to the database
00161                 $this->dbLayer->connectToDatabase();
00162 
00163                 // Ask the database layer
00164                 $this->dbLayer->queryUpdateDataSet($dataSetInstance);
00165         }
00166 
00173         public function getPrimaryKeyOfTable ($tableName) {
00174                 // Connect to the database
00175                 $this->dbLayer->connectToDatabase();
00176 
00177                 // Ask the database layer
00178                 $primaryKey = $this->dbLayer->getPrimaryKeyOfTable($tableName);
00179 
00180                 // Return the value
00181                 return $primaryKey;
00182         }
00183 }
00184 
00185 // [EOF]
00186 ?>

Generated on Mon Dec 8 01:06:46 2008 for Ship-Simulator by  doxygen 1.5.6