nmps-server

server-side nmps
git clone git://git.kocotian.pl/nmps-server.git
Log | Files | Refs | README

commit 3e3e8fcb84d946be1a50fdd679ed994374f61ca2
parent c52ce1e527b8e74ad4a38830cae500fc4671bff3
Author: kocotian <kocotian@kocotian.pl>
Date:   Sun, 29 Nov 2020 19:36:59 +0100

dbconnect removal

Diffstat:
AREADME.md | 15+++++++++++++++
Drequire/argv.php | 2--
Drequire/dbconnect.php | 9---------
Drequire/dbutils.php | 34----------------------------------
Mrequire/nmps.php | 2+-
5 files changed, 16 insertions(+), 46 deletions(-)

diff --git a/README.md b/README.md @@ -0,0 +1,15 @@ +# Configuration +To properly configure nmps, create in nmps parent directory file `nmpsdb.php` with contents: +``` +<?php + + return + [ + "host" => "<DATABASE HOST>", + "username" => "<DATABASE USERNAME>", + "password" => "<DATABASE PASSWORD>", + "database" => "<DATABASE NAME>" + ]; +``` + +File is in parent directory in terms of security. diff --git a/require/argv.php b/require/argv.php @@ -1,2 +0,0 @@ -<?php -$argv = explode("\1", $_SERVER['HTTP_ARGV']); diff --git a/require/dbconnect.php b/require/dbconnect.php @@ -1,9 +0,0 @@ -<?php - - return - [ - "host" => "<MYSQL DATABASE HOST>", - "username" => "<MYSQL DATABASE USERNAME>", - "password" => "<MYSQL DATABASE PASSWORD>", - "database" => "<MYSQL DATABASE NAME>" - ]; diff --git a/require/dbutils.php b/require/dbutils.php @@ -1,34 +0,0 @@ -<?php - - class db - { - private static function connect() - { - try - { - $dbCredentials = require("dbconnect.php"); - $pdo = new PDO("mysql:host={$dbCredentials['host']};dbname={$dbCredentials['database']};charset=utf8", $dbCredentials['username'], $dbCredentials['password'], [ - PDO::ATTR_EMULATE_PREPARES => false, - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION - ]); - return $pdo; - } - catch(PDOException $error) - { - exit("Database error"); - } - } - - public static function query($query, $parameters = []) - { - $statement = self::connect() -> prepare($query); - $statement -> execute($parameters); - if(explode(' ', $query)[0] == 'SELECT') - { - $data = $statement -> fetchAll(); - return $data; - } - } - } - -?> diff --git a/require/nmps.php b/require/nmps.php @@ -18,7 +18,7 @@ class db { try { - $dbCredentials = require("dbconnect.php"); + $dbCredentials = require("../nmpsdb.php"); $pdo = new PDO("mysql:host={$dbCredentials['host']};dbname={$dbCredentials['database']};charset=utf8", $dbCredentials['username'], $dbCredentials['password'], [ PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION