Skip to content

Commit

Permalink
Updated database config structure for multiple connections and demos
Browse files Browse the repository at this point in the history
  • Loading branch information
judus committed Mar 31, 2018
1 parent 60fb9c6 commit f137ca3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
8 changes: 5 additions & 3 deletions app/Demo/ORM/Config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
use App\Demo\ORM\Entities\Role;
use App\Demo\ORM\Entities\User;
use App\Demo\ORM\Entities\Usertype;
use Maduser\Minimal\Database\Connectors\PDO;
use Maduser\Minimal\Framework\Facades\Config;
use Maduser\Minimal\Database\DB;

/** @var \Maduser\Minimal\Routing\Router $router */

$router->get('orm', function () {

PDO::connection(Config::item('database'));
DB::connections(Config::database());

// Getting instances
$user = User::instance();
Expand Down Expand Up @@ -115,5 +115,7 @@
// Eager loading relationships
$user->with(['type', 'profile', 'roles', 'posts', 'comments'])->getAll();

return count(PDO::getExecutedQueries()) . ' queries have been executed.';
return 'Connector \'' . DB::connector()->getName() . '\' has executed ' .
count(DB::connector()->getExecutedQueries()) . ' queries in database \''
. DB::connector()->getDatabase() . '\' ' . show(DB::connector()->getExecutedQueries(), null, true);
});
24 changes: 13 additions & 11 deletions config/minimal.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,19 @@
// DATABASE

'database' => [
'driver' => 'mysql',
'host' => 'localhost',
'port' => '3306',
'user' => '',
'password' => '',
'database' => '',
'charset' => 'utf8',
'handler' => \PDO::class,
'handlerOptions' => [
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
\PDO::ATTR_EMULATE_PREPARES => false
'default' => [
'driver' => 'mysql',
'host' => 'localhost',
'port' => '3306',
'user' => '',
'password' => '',
'database' => '',
'charset' => 'utf8',
'handler' => \PDO::class,
'handlerOptions' => [
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
\PDO::ATTR_EMULATE_PREPARES => false
]
]
],

Expand Down
3 changes: 1 addition & 2 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@

// Test the database connection
Router::get('database', function () {
PDO::connection(Config::item('database'));

DB::connections(Config::database());
return 'Successfully connected to database';
});

Expand Down

0 comments on commit f137ca3

Please sign in to comment.