add SQCManager
This commit is contained in:
31
geoapi/api/Api.php
Normal file
31
geoapi/api/Api.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
include_once "../../global.inc.php";
|
||||
include_once PATH_DATABASE . "/SQLManager.php";
|
||||
require_once PATH_3PARTY . "/Slim/Slim.php";
|
||||
\Slim\Slim::registerAutoloader();
|
||||
|
||||
abstract class Api extends \Slim\Slim {
|
||||
|
||||
protected $sqlManager;
|
||||
|
||||
public function __construct() {
|
||||
if (!$this->sqlManager) {
|
||||
echo "bla";
|
||||
$this->sqlManager = new SQLManager();
|
||||
}
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
$this->sqlManager = null;
|
||||
//parent::__destruct();
|
||||
}
|
||||
|
||||
public function connect() {
|
||||
$this->sqlManager->connect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
27
geoapi/api/SpsApi.php
Normal file
27
geoapi/api/SpsApi.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
include_once "../../global.inc.php";
|
||||
|
||||
require_once PATH_API."/Api.php";
|
||||
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description of HelloApi
|
||||
*
|
||||
* @author stubbfel
|
||||
*/
|
||||
class SpsApi extends Api{
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
parent::__destruct();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
26
geoapi/database/HelloApiSQLManager.php
Normal file
26
geoapi/database/HelloApiSQLManager.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
include_once "../../global.inc.php";
|
||||
include_once PATH_DATABASE . "/SQLManager.php";
|
||||
|
||||
/**
|
||||
* The SQLManager manage the SQL-Connection for an API
|
||||
*
|
||||
* @author stubbfel
|
||||
*/
|
||||
class HelloApiSQLManager extends SQLManager{
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
public function sendHelloQuery() {
|
||||
return $this->query("SELECT * FROM sps");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
60
geoapi/database/SQLManager.php
Normal file
60
geoapi/database/SQLManager.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
include_once "../../global.inc.php";
|
||||
|
||||
/**
|
||||
* The SQLManager manage the SQL-Connection for an API
|
||||
*
|
||||
* @author stubbfel
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
14
geoapi/database/SpsSqlManager.php
Normal file
14
geoapi/database/SpsSqlManager.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
include_once "../../global.inc.php";
|
||||
include_once PATH_DATABASE . "/SQLManager.php";
|
||||
|
||||
/**
|
||||
* Description of SpsSqlManager
|
||||
*
|
||||
* @author stubbfel
|
||||
*/
|
||||
class SpsSqlManager {
|
||||
//put your code here
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,7 +1,8 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
$sqlServer = "localhost";
|
||||
$sqlDBName = "geoDB";
|
||||
$sqlDBUser = "geoDB";
|
||||
$sqlDBUserPW = "VZrSAYvmcrntQ97b"
|
||||
|
||||
?>
|
||||
|
||||
@@ -3,5 +3,5 @@ define("PATH_ROOT", dirname(__FILE__));
|
||||
define("PATH_SERVICES", PATH_ROOT. "/service");
|
||||
define("PATH_3PARTY", PATH_ROOT . "/thirdparty");
|
||||
define("PATH_API", PATH_ROOT . "/api");
|
||||
define("PATH_DATABASE", PATH_ROOT. "/datebase");
|
||||
define("PATH_DATABASE", PATH_ROOT. "/database");
|
||||
?>
|
||||
|
||||
34
geoapi/service/helloservice/HelloApi.php
Normal file
34
geoapi/service/helloservice/HelloApi.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
include_once "../../global.inc.php";
|
||||
include_once PATH_DATABASE . "/HelloApiSQLManager.php";
|
||||
require_once PATH_API . "/Api.php";
|
||||
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Description of HelloApi
|
||||
*
|
||||
* @author stubbfel
|
||||
*/
|
||||
class HelloApi extends Api {
|
||||
|
||||
public function __construct() {
|
||||
$this->sqlManager = new HelloApiSQLManager();
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function __destruct() {
|
||||
parent::__destruct();
|
||||
}
|
||||
|
||||
public function sendHelloQuery() {
|
||||
return $this->sqlManager->sendHelloQuery();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -1,11 +1,14 @@
|
||||
|
||||
<?php
|
||||
include_once "../../global.inc.php";
|
||||
require_once PATH_API."/api.php";
|
||||
require_once "HelloApi.php";
|
||||
|
||||
$app = new api();
|
||||
|
||||
$app = new HelloApi();
|
||||
|
||||
$app->get('/hello/:name', function ($name) {
|
||||
$app->get('/hello/:name', function ($name) use ($app) {
|
||||
$app->connect();
|
||||
print_r($app->sendHelloQuery());
|
||||
// print
|
||||
echo "Hello, $name";
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user