serverAddress = \config\DBConfig::$sqlServer; $this->dbName = \config\DBConfig::$sqlDBName; $this->userName = \config\DBConfig::$sqlDBUser; $this->userPw = \config\DBConfig::$sqlDBUserPW; } /** * Default-DEConstructor */ public function __destruct() { $this->closeConnection(); $this->serverAddress = null; $this->dbName = null; $this->userName = null; $this->userPW = null; } /** * Method setup the connection to the Database */ public function connect() { $this->link = mysql_connect($this->serverAddress, $this->userName, $this->userPw); if (!$this->link) { exit("No Connection: " . mysql_error()); } $selected = mysql_select_db($this->dbName, $this->link); if (!$selected) { exit("No DB: " . mysql_error()); } } /** * Method close the connection */ public function closeConnection() { if ($this->link) { mysql_close($this->link); $this->link = null; } } /** * Method send a query to the Datebase and return the result * @param string $query * @return result[num][assoc] */ protected function query($query) { $mysqlResult = mysql_query($query, $this->link); if (!$mysqlResult) { exit("Query error: " . mysql_error()); } $rowNums = mysql_num_rows($mysqlResult); $result = array(); for ($i = 0; $i < $rowNums; $i++) { $row = mysql_fetch_assoc($mysqlResult); $result[$i] = $row; } mysql_free_result($mysqlResult); return $result; } /** * Method if the string is not a empty String (not only spaces and controlls) * @param string $string * @return boolean */ protected function validString($string) { if (!ctype_space($string) && !ctype_cntrl($string)) { return TRUE; } return FALSE; } } ?>