Skip to content

Commit

Permalink
Updated the Database Credential Check
Browse files Browse the repository at this point in the history
The previous version had a major bug, making it difficult for Paperwork to run.
  • Loading branch information
Liongold authored Aug 8, 2016
1 parent 1637db7 commit 1bd410f
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions frontend/public/setup/check_database_credentials.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<?php

if(!file_exists("../../app/storage/config/database1.json")) {
if(!file_exists("../../app/storage/config/database.json")) {

try {
if($_GET['driver'] === "mysql") {
$connection = new PDO("mysql:host=".$_GET['host'].";port=".$_GET['port'].";dbname=".$_GET['database'], $_GET['username'], $_GET['password']);
}else if($_GET['driver'] === 'pgsql') {
$connection = new PDO("pgsql:host=".$_GET['host'].";port=".$_GET['port'].";dbname=".$_GET['database'].";user=".$_GET['username'].";password=".$_GET['password']);
}else if($_GET['driver'] === 'sqlite') {
if($_POST['driver'] === "mysql") {
$connection = new PDO("mysql:host=".$_POST['host'].";port=".$_POST['port'].";dbname=".$_POST['database'], $_POST['username'], $_POST['password']);
}else if($_POST['driver'] === 'pgsql') {
$connection = new PDO("pgsql:host=".$_POST['host'].";port=".$_POST['port'].";dbname=".$_POST['database'].";user=".$_POST['username'].";password=".$_POST['password']);
}else if($_POST['driver'] === 'sqlite') {
$connection = new PDO("sqlite::memory:");
}else if($_GET['driver'] === 'sqlsrv') {
$connection = new PDO("sqlsrv:Server=".$_GET['host'].",".$_GET['port'].";Database=".$_GET['database'], $_GET['username'], $_GET['password']);
}else if($_POST['driver'] === 'sqlsrv') {
$connection = new PDO("sqlsrv:Server=".$_POST['host'].",".$_POST['port'].";Database=".$_POST['database'], $_POST['username'], $_POST['password']);
}


$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$string = array(
'driver' => $_POST['driver'],
'database' => $_POST['database'],
Expand All @@ -21,13 +23,19 @@
'password' => $_POST['password'],
'port' => $_POST['port']
);

file_put_contents("../../app/storage/config/database1.json", json_encode($string));


file_put_contents("../../app/storage/config/database.json", json_encode($string));

try{
$test = $connection->query("SELECT * FROM migrations LIMIT 1");
}catch(Exception $error) {
exec("cd ../../ && php artisan migrate --force");
}

header("Location: ".$_SERVER['HTTP_REFERRER'], true, 200);

}catch(PDOException $e) {
header("Location: ".$_SERVER['HTTP_REFERRER'], true, 404);
}
}

}

0 comments on commit 1bd410f

Please sign in to comment.