diff --git a/geoapi/api/Api.php b/geoapi/api/Api.php new file mode 100644 index 0000000..fd49962 --- /dev/null +++ b/geoapi/api/Api.php @@ -0,0 +1,31 @@ +sqlManager) { + echo "bla"; + $this->sqlManager = new SQLManager(); + } + parent::__construct(); + } + + public function __destruct() { + $this->sqlManager = null; + //parent::__destruct(); + } + + public function connect() { + $this->sqlManager->connect(); + } + +} + +?> diff --git a/geoapi/api/SpsApi.php b/geoapi/api/SpsApi.php new file mode 100644 index 0000000..11c9701 --- /dev/null +++ b/geoapi/api/SpsApi.php @@ -0,0 +1,27 @@ + diff --git a/geoapi/database/HelloApiSQLManager.php b/geoapi/database/HelloApiSQLManager.php new file mode 100644 index 0000000..27914e3 --- /dev/null +++ b/geoapi/database/HelloApiSQLManager.php @@ -0,0 +1,26 @@ +query("SELECT * FROM sps"); + } + +} + +?> diff --git a/geoapi/database/SQLManager.php b/geoapi/database/SQLManager.php new file mode 100644 index 0000000..6cafa0d --- /dev/null +++ b/geoapi/database/SQLManager.php @@ -0,0 +1,60 @@ +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; + } + +} + +?> diff --git a/geoapi/database/SpsSqlManager.php b/geoapi/database/SpsSqlManager.php new file mode 100644 index 0000000..52e317e --- /dev/null +++ b/geoapi/database/SpsSqlManager.php @@ -0,0 +1,14 @@ + diff --git a/geoapi/database/mysql.php b/geoapi/database/mysql.php index 3e558ca..4dcf117 100644 --- a/geoapi/database/mysql.php +++ b/geoapi/database/mysql.php @@ -1,7 +1,8 @@ diff --git a/geoapi/global.inc.php b/geoapi/global.inc.php index 16ce1c5..018a756 100644 --- a/geoapi/global.inc.php +++ b/geoapi/global.inc.php @@ -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"); ?> diff --git a/geoapi/service/helloservice/HelloApi.php b/geoapi/service/helloservice/HelloApi.php new file mode 100644 index 0000000..4e8965a --- /dev/null +++ b/geoapi/service/helloservice/HelloApi.php @@ -0,0 +1,34 @@ +sqlManager = new HelloApiSQLManager(); + parent::__construct(); + } + + public function __destruct() { + parent::__destruct(); + } + + public function sendHelloQuery() { + return $this->sqlManager->sendHelloQuery(); + } + +} + +?> diff --git a/geoapi/service/helloservice/index.php b/geoapi/service/helloservice/index.php index 42aaa2d..f7d29d3 100644 --- a/geoapi/service/helloservice/index.php +++ b/geoapi/service/helloservice/index.php @@ -1,11 +1,14 @@ - get('/hello/:name', function ($name) { +$app->get('/hello/:name', function ($name) use ($app) { + $app->connect(); + print_r($app->sendHelloQuery()); + // print echo "Hello, $name"; });