Overview

Namespaces

  • api
  • config
  • database
  • PHP
  • Slim
    • Exception
    • Http
    • Middleware
  • utiliy

Classes

  • PisSqlManager
  • PssSqlManager
  • SpsSqlManager
  • SqlManager
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: namespace database;
  4: 
  5: include_once "../../global.inc.php";
  6: include_once PATH_CONFIG . "/config.db.php";
  7: 
  8: /**
  9:  * The SQLManager manage the SQL-Connection for an API
 10:  * @author stubbfel
 11:  * @since 20.06.2013
 12:  */
 13: abstract class SqlManager {
 14: 
 15:     /**
 16:      * Variable for address of the server
 17:      * @var string
 18:      */
 19:     private $serverAddress;
 20: 
 21:     /**
 22:      * Variable for name of the databaseuser
 23:      * @var string
 24:      */
 25:     private $userName;
 26: 
 27:     /**
 28:      * Variable for name of the database
 29:      * @var string
 30:      */
 31:     private $dbName;
 32: 
 33:     /**
 34:      * Variable for password of the user
 35:      * @var string
 36:      */
 37:     private $userPw;
 38: 
 39:     /**
 40:      * Variable for link of the connection to the server
 41:      * @var connection
 42:      */
 43:     private $link;
 44: 
 45:     /**
 46:      * String for an and-operrator
 47:      * @var string
 48:      */
 49:     protected $andTerm = " and ";
 50: 
 51:     /**
 52:      * String for an or-operrator
 53:      * @var string
 54:      */
 55:     protected $orTerm = " or ";
 56: 
 57:     /**
 58:      * String for quotes in a query
 59:      * @var string
 60:      */
 61:     protected $quoteTerm = "\"";
 62: 
 63:     /**
 64:      * Default-Constructor
 65:      */
 66:     public function __construct() {
 67:         $this->serverAddress = \config\DBConfig::$sqlServer;
 68:         $this->dbName = \config\DBConfig::$sqlDBName;
 69:         $this->userName = \config\DBConfig::$sqlDBUser;
 70:         $this->userPw = \config\DBConfig::$sqlDBUserPW;
 71:     }
 72: 
 73:     /**
 74:      * Default-DEConstructor
 75:      */
 76:     public function __destruct() {
 77:         
 78:         // close connection
 79:         $this->closeConnection();
 80:         
 81:         // delete connection parameter
 82:         unset($this->serverAddress);
 83:         unset($this->dbName);
 84:         unset($this->userName);
 85:         unset($this->userPW);
 86:     }
 87: 
 88:     /**
 89:      * Method setup the connection to the Database
 90:      */
 91:     public function connect() {
 92:         $this->link = mysql_connect($this->serverAddress, $this->userName, $this->userPw);
 93:         if (!$this->link) {
 94:             exit("No Connection: " . mysql_error());
 95:         }
 96:         $selected = mysql_select_db($this->dbName, $this->link);
 97:         if (!$selected) {
 98:             exit("No DB: " . mysql_error());
 99:         }
100:     }
101: 
102:     /**
103:      * Method close the connection
104:      */
105:     public function closeConnection() {
106:         if ($this->link) {
107:             mysql_close($this->link);
108:             unset($this->link);
109:             $this->link = null;
110:         }
111:     }
112: 
113:     /**
114:      * Method send a query to the Datebase and return the result
115:      * @param string $query
116:      * @return result[num][assoc]
117:      */
118:     protected function query($query) {
119:         
120:         // send error
121:         $mysqlResult = mysql_query($query, $this->link);
122:         if (!$mysqlResult) {
123:             exit("Query error: " . mysql_error());
124:         }
125:         
126:         // fetch result
127:         $rowNums = mysql_num_rows($mysqlResult);
128:         $result = array();
129:         for ($i = 0; $i < $rowNums; $i++) {
130:             $row = mysql_fetch_assoc($mysqlResult);
131:             $result[$i] = $row;
132:         }
133:         
134:         // call gc
135:         mysql_free_result($mysqlResult);
136:         
137:         return $result;
138:     }
139: }
140: 
141: ?>
142: 
GeoApi API documentation generated by ApiGen 2.8.0