This commit is contained in:
Leander
2017-03-02 11:19:26 +01:00
commit 8083f5568f
5 changed files with 84 additions and 0 deletions

26
Database.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
/**
* Created by PhpStorm.
* User: leanderschmedemann
* Date: 02/03/2017
* Time: 09:59
*/
class Database
{
private $db;
function __construct() {
$this->db = pg_connect("host=".DATABASE_URL." dbmane=".DATABASE_NAME." user=".DATABASE_USER." password=".DATABASE_PASSWORD);
}
function query($sql) {
$result = pg_query($this->db, $sql);
if(!$result) {
echo json_encode(array("error"=>1));
exit;
}
$arr = pg_fetch_all($result);
return $arr;
}
}

15
config.inc.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
/**
* Created by PhpStorm.
* User: leanderschmedemann
* Date: 02/03/2017
* Time: 09:45
*/
define("DATABASE_URL", 'lamp.wlan.hwr-berlin.de');
define("DATABASE_USER", 'gr2');
define("DATABASE_PASSWORD", '2Au-R2n-cQN-uuG');
define("DATABASE_NAME", 'CSDB');
// TODO
?>

14
includes.inc.php Normal file
View File

@@ -0,0 +1,14 @@
<?php
/**
* Created by PhpStorm.
* User: leanderschmedemann
* Date: 02/03/2017
* Time: 09:47
*/
//include include files
require_once('config.inc.php');
require_once('Database.php');
?>

11
index.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
/**
* Created by PhpStorm.
* User: leanderschmedemann
* Date: 02/03/2017
* Time: 09:43
*/
echo "This is an API. Specs can be found at /dev/null."
?>

18
register.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
/**
* Created by PhpStorm.
* User: leanderschmedemann
* Date: 02/03/2017
* Time: 10:23
*/
require_once('includes.inc.php');
$name = $_GET['name'];
$database = new Database();
$result = $database->query('SELECT * FROM CATEGORIES');
print nl2br(print_r($name, true));
print nl2br(print_r($result, true));
?>