This commit is contained in:
stubbfel
2013-07-10 11:34:07 +02:00
parent 5c11441ef5
commit fe6e6eaaf4
7 changed files with 163 additions and 67 deletions

View File

@@ -60,6 +60,18 @@ abstract class SqlManager {
*/
protected static $quoteTerm = "\"";
/**
* String for open Bracket in a query
* @var string
*/
protected static $openBracket = "(";
/**
* String for close Bracket in a query
* @var string
*/
protected static $closeBracket = ")";
/**
* Default-Constructor
*/
@@ -67,7 +79,9 @@ abstract class SqlManager {
$this->serverAddress = \config\DBConfig::$sqlServer;
$this->dbName = \config\DBConfig::$sqlDBName;
$this->userName = \config\DBConfig::$sqlDBUser;
$this->userPw = \config\DBConfig::$sqlDBUserPW;
$this->userPw = \config\DBConfig::$sqlDBUserPW
;
}
/**
@@ -82,18 +96,20 @@ abstract class SqlManager {
unset($this->serverAddress);
unset($this->dbName);
unset($this->userName);
unset($this->userPW);
unset($this->userPW
);
}
/**
* Method setup the connection to the Database
*/
public function connect() {
$this->link = mysql_connect($this->serverAddress, $this->userName, $this->userPw);
$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);
$selected = mysql_select_db($this->dbName , $this->link);
if (!$selected) {
exit("No DB: " . mysql_error());
}
@@ -103,7 +119,9 @@ abstract class SqlManager {
* Method close the connection
*/
public function closeConnection() {
if ($this->link) {
if (
$this->link) {
mysql_close($this->link);
unset($this->link);
$this->link = null;
@@ -113,20 +131,23 @@ abstract class SqlManager {
/**
* Method send a query to the Datebase and return the result
* @param string $query
* @return result[num][assoc]
*/
protected function query($query) {
// send error
$mysqlResult = mysql_query($query, $this->link);
$mysqlResult = mysql_query($query, $this->link );
if (!$mysqlResult) {
// echo $query;
exit("Query error: " . mysql_error());
}
// fetch result
$rowNums = mysql_num_rows($mysqlResult);
$result = array();
for ($i = 0; $i < $rowNums; $i++) {
for ($i = 0; $i < $rowNums; $i++) {
$row = mysql_fetch_assoc($mysqlResult);
$result[$i] = $row;
}