-
Notifications
You must be signed in to change notification settings - Fork 4
/
pdo.inc
55 lines (41 loc) · 1.25 KB
/
pdo.inc
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
48
49
50
51
52
53
54
55
<?php
/*.
require_module 'pdo';
.*/
require __DIR__.'/vendor/autoload.php';
$dotenv = Dotenv\Dotenv::create(__DIR__);
$dotenv->load();
class MyPDO
{
protected static /*.PDO.*/ $my_instance = null;
public static function instance()
{
if (self::$my_instance === null) {
// Setup a DB connecition via the parent PDO
// (In this case, MySQL Specific)
$options = [
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => 1,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
];
$username = $_ENV['DBUSER'];
$password = $_ENV['DBPASS'];
$charset = 'utf8';
$dsn = 'mysql:';
$dsn .= 'host='.$_ENV['DBHOST'];
$dsn .= ';dbname='.$_ENV['DBNAME'];
$dsn .= ';charset='.$charset;
try {
self::$my_instance = new PDO($dsn, $username, $password, $options);
} catch (Exception $e) {
throw $e;
}
}
return self::$my_instance;
}
public static function __callStatic($method, $args)
{
return call_user_func_array(array(self::instance(), $method), $args);
}
/* end */
}