-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.php
47 lines (37 loc) · 1.43 KB
/
db.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
require('vendor/autoload.php');
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Events\Dispatcher;
use Illuminate\Container\Container;
class Db{
public $Capsule;
public function CreateCapsule($driver, $host, $username, $password, $database){
$this->Capsule = new Capsule;
$this->Capsule->addConnection([
'driver' => $driver,
'host' => $host,
'database' => $database,
'username' => $username,
'password' => $password,
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]);
// Set the event dispatcher used by Eloquent models... (optional)
$this->Capsule->setEventDispatcher(new Dispatcher(new Container));
// Make this Capsule instance available globally via static methods... (optional)
$this->Capsule->setAsGlobal();
// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$this->Capsule->bootEloquent();
}
public function CreateMyCapsule($host, $username, $password, $database){
$driver = 'mysql';
$this->CreateCapsule($driver, $host, $username, $password, $database);
}
public static function Create($host, $username, $password, $database){
$db = new Db();
$db->CreateMyCapsule($host, $username, $password, $database);
return $db;
}
}
?>