Overview

Namespaces

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

Classes

  • 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:      * Default-Constructor
 47:      */
 48:     public function __construct() {
 49:        
 50:         $this->serverAddress = \config\DBConfig::$sqlServer;
 51:         $this->dbName = \config\DBConfig::$sqlDBName;
 52:         $this->userName = \config\DBConfig::$sqlDBUser;
 53:         $this->userPw = \config\DBConfig::$sqlDBUserPW;
 54:     }
 55: 
 56:     /**
 57:      * Default-DEConstructor
 58:      */
 59:     public function __destruct() {
 60:         $this->closeConnection();
 61:         $this->serverAddress = null;
 62:         $this->dbName = null;
 63:         $this->userName = null;
 64:         $this->userPW = null;
 65:     }
 66: 
 67:     /**
 68:      * Method setup the connection to the Database
 69:      */
 70:     public function connect() {
 71:         $this->link = mysql_connect($this->serverAddress, $this->userName, $this->userPw);
 72:         if (!$this->link) {
 73:             exit("No Connection: " . mysql_error());
 74:         }
 75:         $selected = mysql_select_db($this->dbName, $this->link);
 76:         if (!$selected) {
 77:             exit("No DB: " . mysql_error());
 78:         }
 79:     }
 80: 
 81:     /**
 82:      * Method close the connection
 83:      */
 84:     public function closeConnection() {
 85:         if ($this->link) {
 86:             mysql_close($this->link);
 87:             $this->link = null;
 88:         }
 89:     }
 90: 
 91:     /**
 92:      * Method send a query to the Datebase and return the result
 93:      * @param string $query
 94:      * @return result[num][assoc]
 95:      */
 96:     protected function query($query) {
 97:         $mysqlResult = mysql_query($query, $this->link);
 98:         if (!$mysqlResult) {
 99:             exit("Query error: " . mysql_error());
100:         }
101:         $rowNums = mysql_num_rows($mysqlResult);
102:         $result = array();
103:         for ($i = 0; $i < $rowNums; $i++) {
104:             $row = mysql_fetch_assoc($mysqlResult);
105:             $result[$i] = $row;
106:         }
107:         mysql_free_result($mysqlResult);
108:         return $result;
109:     }
110: 
111: }
112: 
113: ?>
114: 
GeoApi API documentation generated by ApiGen 2.8.0