feat: allow for SQL server port specification

This commit is contained in:
David Bailey 2023-12-12 22:39:06 +01:00
parent 0d9bedcaca
commit 9e855fba36
3 changed files with 20 additions and 16 deletions

View file

@ -6,10 +6,11 @@ services:
ports: ports:
- 8081:80 - 8081:80
environment: environment:
MYSQL_HOST: mysql
MYSQL_USER: root MYSQL_USER: root
MYSQL_PASSWORD: example MYSQL_PASSWORD: example
MYSQL_DATABASE: dragon_fire MYSQL_DATABASE: dragon_fire
MYSQL_HOST: mysql
MYSQL_PORT: 3306
develop: develop:
watch: watch:
- path: ./ - path: ./

View file

@ -9,24 +9,29 @@ class MySQLAdapter {
function __construct() { function __construct() {
$db_params = json_decode(file_get_contents('secrets/db.json'), true); $db_params = json_decode(file_get_contents('secrets/db.json'), true);
if(null !== getenv('MYSQL_HOST')) { try {
$this->raw = mysqli_connect(getenv('MYSQL_HOST'), if(false !== getenv('MYSQL_HOST')) {
getenv('MYSQL_USER'), getenv('MYSQL_PASSWORD'), getenv('MYSQL_DATABASE')); $this->raw = mysqli_connect(getenv('MYSQL_HOST'),
} getenv('MYSQL_USER'), getenv('MYSQL_PASSWORD'),
else { getenv('MYSQL_DATABASE'),
$this->raw = mysqli_connect($db_params['MYSQL_HOST'], getenv('MYSQL_PORT'));
$db_params['MYSQL_USER'], $db_params['MYSQL_PASSWORD'], $db_params['MYSQL_DATABASE']); }
} else {
$this->raw = mysqli_connect($db_params['MYSQL_HOST'],
$this->data_directory = 'raw'; $db_params['MYSQL_USER'], $db_params['MYSQL_PASSWORD'],
$db_params['MYSQL_DATABASE'],
if (!$this->raw) $db_params['MYSQL_PORT']);
{ }
} catch (\Throwable $th) {
echo 'Connection failed<br>'; echo 'Connection failed<br>';
echo 'Error number: ' . mysqli_connect_errno() . '<br>'; echo 'Error number: ' . mysqli_connect_errno() . '<br>';
echo 'Error message: ' . mysqli_connect_error() . '<br>'; echo 'Error message: ' . mysqli_connect_error() . '<br>';
die(); die();
//throw $th;
} }
$this->data_directory = 'raw';
} }
function _exec($qery, $argtypes, ...$args) { function _exec($qery, $argtypes, ...$args) {

View file

@ -49,8 +49,6 @@ if($SURI == '/') {
} elseif($SURI == '/api/upload') { } elseif($SURI == '/api/upload') {
if(array_key_exists('post_data', $_FILES)) { if(array_key_exists('post_data', $_FILES)) {
$adapter->handle_upload($_POST['post_path'], $_FILES['post_data']['tmp_name']); $adapter->handle_upload($_POST['post_path'], $_FILES['post_data']['tmp_name']);
} }