add sps service
This commit is contained in:
61
geoapi/database/SqlManager.php
Normal file
61
geoapi/database/SqlManager.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
include_once "../../global.inc.php";
|
||||
|
||||
/**
|
||||
* The SQLManager manage the SQL-Connection for an API
|
||||
*
|
||||
* @author stubbfel
|
||||
*/
|
||||
abstract class SqlManager {
|
||||
|
||||
private $serverAddress;
|
||||
private $userName;
|
||||
private $dbName;
|
||||
private $userPw;
|
||||
private $link;
|
||||
|
||||
public function __construct() {
|
||||
include_once PATH_DATABASE . "/mysql.php";
|
||||
$this->serverAddress = $sqlServer;
|
||||
$this->dbName = $sqlDBName;
|
||||
$this->userName = $sqlDBUser;
|
||||
$this->userPw = $sqlDBUserPW;
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
$this->close();
|
||||
$this->serverAddress = null;
|
||||
$this->dbName = null;
|
||||
$this->userName = null;
|
||||
$this->userPW = null;
|
||||
}
|
||||
|
||||
public function connect() {
|
||||
$this->link = mysql_connect($this->serverAddress, $this->userName, $this->userPw) or die("No Connection: " . mysql_error());
|
||||
mysql_select_db($this->dbName, $this->link) or die("No DB: " . mysql_error());
|
||||
}
|
||||
|
||||
public function close() {
|
||||
if ($this->link) {
|
||||
mysql_close($this->link);
|
||||
$this->link =null;
|
||||
}
|
||||
}
|
||||
|
||||
protected function query($query) {
|
||||
$mysqlResult = mysql_query($query, $this->link) or die("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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user