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
00036 private $dbLayer = null;
00037
00038
00039 private static $thisInstance = null;
00040
00046 protected function __construct() {
00047
00048 parent::__construct(__CLASS__);
00049 }
00050
00051
00052 public final static function createDatabaseConnection (DebugMiddleware $debugInstance, DatabaseFrontendInterface $dbLayer) {
00053
00054 $dbInstance = new DatabaseConnection();
00055
00056
00057 $dbInstance->setDebugInstance($debugInstance);
00058
00059
00060 $dbInstance->setDatabaseLayer($dbLayer);
00061
00062
00063 self::$thisInstance = $dbInstance;
00064
00065
00066 return $dbInstance;
00067 }
00068
00069
00070 public final static function getInstance () {
00071 return self::$thisInstance;
00072 }
00073
00074
00075 public final function setConnectionData ($login, $pass, $dbase, $host="localhost") {
00076
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
00120 $this->dbLayer->connectToDatabase();
00121
00122
00123 $result = $this->dbLayer->querySelect("array", $tableName, $criteriaInstance);
00124
00125
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
00147 $this->dbLayer->connectToDatabase();
00148
00149
00150 $this->dbLayer->queryInsertDataSet($dataSetInstance);
00151 }
00152
00159 public function queryUpdateDataSet (StoreableCriteria $dataSetInstance) {
00160
00161 $this->dbLayer->connectToDatabase();
00162
00163
00164 $this->dbLayer->queryUpdateDataSet($dataSetInstance);
00165 }
00166
00173 public function getPrimaryKeyOfTable ($tableName) {
00174
00175 $this->dbLayer->connectToDatabase();
00176
00177
00178 $primaryKey = $this->dbLayer->getPrimaryKeyOfTable($tableName);
00179
00180
00181 return $primaryKey;
00182 }
00183 }
00184
00185
00186 ?>