-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Prequel now uses it's own database instance with the config…
… defined in config/prequel.php
- Loading branch information
1 parent
b5ff88d
commit f1ab336
Showing
5 changed files
with
84 additions
and
23 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
namespace Protoqol\Prequel\Classes\Database; | ||
|
||
use Illuminate\Database\Connection; | ||
use PDO; | ||
|
||
/** | ||
* Class DatabaseConnector | ||
* | ||
* @package Protoqol\Prequel\Classes\Database | ||
*/ | ||
class DatabaseConnector | ||
{ | ||
|
||
public $connection; | ||
|
||
/** | ||
* @return \Illuminate\Database\Connection | ||
*/ | ||
public function getConnection() | ||
{ | ||
$this->connection = (new Connection($this->getPdo())); | ||
return $this->connection; | ||
} | ||
|
||
/** | ||
* @return \PDO | ||
*/ | ||
private function getPdo() | ||
{ | ||
$dsn = $this->constructDsn(); | ||
$user = config('prequel.DB.USERNAME'); | ||
$pass = config('prequel.DB.PASSWORD'); | ||
|
||
return new PDO($dsn, $user, $pass); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
private function constructDsn() | ||
{ | ||
$connection = config('prequel.DB.CONNECTION'); | ||
$databaseName = config('prequel.DB.DATABASE'); | ||
$host = config('prequel.DB.HOST'); | ||
|
||
return $connection.':dbname='.$databaseName.';host='.$host; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters