# DB

class DB

## Methods

`public static` | `` | `create()` | No description |
`public static` | `` | `mysql($env)` | No description |
`public static` | `` | `getConn($env = null)` | No description |

## Details

at line 11

### `create()`

`public static create()`
at line 18

### `mysql()`

`public static mysql($env)`

#### Parameters

| `$env` |

at line 29

### `getConn()`

`public static getConn($env = null)`

#### Parameters

| `$env` |

## Source code

    <?php

        namespace App\Khan\Component\DB;
        use Medoo\Medoo;

        class DB {

            private static $db = null;
            private static $instance = null;

            public static function create(){
                if (!self::$instance) {
                    self::$instance = new DB();
                }
                return self::$instance;
            }

            public static function mysql($env){
                return [
                  'database_type' => $env['DB_CONNECTION'] ?: "mysql",
                  'database_name' => $env['DB_DATABASE'] ?: "",
                  'server' => $env['DB_HOST'] ?: "localhost",
                  'username' => $env['DB_USERNAME'] ?: "root",
                  'password' => $env['DB_PASSWORD'] ?: null,
                  'charset' => $env['DB_CHARSET'] ?: "utf-8"
                ];
            }

            public static function getConn($env = null) {
                if (self::$db === null && $env !== null) {
                    $type = "App\Khan\Component\DB\DB::" . $env['DB_CONNECTION'] ?: "mysql";
                    self::$db = new Medoo($type($env));
                }
                return self::$db;
            }

        }