src/Connection.php
public static function connect($dsn, $user = null, $password = null, $args = [])
    {
        // If it's already PDO object, then we simply use it
        if ($dsn instanceof \PDO) {
            $driver = $dsn->getAttribute(\PDO::ATTR_DRIVER_NAME);
            $connectionClass = '\\atk4\\dsql\\Connection';
            $queryClass = null;
            $expressionClass = null;
            switch ($driver) {
                case 'pgsql':
                    $connectionClass = '\\atk4\\dsql\\Connection_PgSQL';
                    $queryClass = 'atk4\dsql\Query_PgSQL';
                    break;
                case 'oci':
                    $connectionClass = '\\atk4\\dsql\\Connection_Oracle';
                    break;
                case 'sqlite':
                    $queryClass = 'atk4\dsql\Query_SQLite';
                    break;
                case 'mysql':
                    $expressionClass = 'atk4\dsql\Expression_MySQL';
                default:
                    // Default, for backwards compatibility
                    $queryClass = 'atk4\dsql\Query_MySQL';
                    break;

            }

            return new $connectionClass(array_merge([
                    'connection'       => $dsn,
                    'query_class'      => $queryClass,
                    'expression_class' => $expressionClass,
                ], $args));
        }

        // If it's some other object, then we simply use it trough proxy connection
        if (is_object($dsn)) {
            return new Connection_Proxy(array_merge([
                    'connection'       => $dsn,
                ], $args));
        }

        // Process DSN string
        $dsn = static::normalizeDSN($dsn, $user, $password);

        // Create driver specific connection
        switch ($dsn['driver']) {
            case 'mysql':
                $c = new static(array_merge([
                    'connection'       => new \PDO($dsn['dsn'], $dsn['user'], $dsn['pass']),
                    'expression_class' => 'atk4\dsql\Expression_MySQL',
                    'query_class'      => 'atk4\dsql\Query_MySQL',
                ], $args));
                break;

            case 'sqlite':
                $c = new static(array_merge([
                    'connection'       => new \PDO($dsn['dsn'], $dsn['user'], $dsn['pass']),
                    'query_class'      => 'atk4\dsql\Query_SQLite',
                ], $args));
                break;

            case 'oci':
                $c = new Connection_Oracle(array_merge([
                    'connection' => new \PDO($dsn['dsn'], $dsn['user'], $dsn['pass']),
                ], $args));
                break;

            case 'oci12':
                $dsn['dsn'] = str_replace('oci12:', 'oci:', $dsn['dsn']);
                $c = new Connection_Oracle12(array_merge([
                    'connection' => new \PDO($dsn['dsn'], $dsn['user'], $dsn['pass']),
                ], $args));
                break;

            case 'pgsql':
                $c = new Connection_PgSQL(array_merge([
                    'connection' => new \PDO($dsn['dsn'], $dsn['user'], $dsn['pass']),
                ], $args));
                break;

            case 'dumper':
                $c = new Connection_Dumper(array_merge([
                    'connection' => static::connect($dsn['rest'], $dsn['user'], $dsn['pass']),
                ], $args));
                break;

            case 'counter':
                $c = new Connection_Counter(array_merge([
                    'connection' => static::connect($dsn['rest'], $dsn['user'], $dsn['pass']),
                ], $args));
                break;

                // let PDO handle the rest
            default:
                $c = new static(array_merge([
                    'connection' => new \PDO($dsn['dsn'], $dsn['user'], $dsn['pass']),
                ], $args));
        }

        return $c;
    }
public static function connect($dsn, $user = null, $password = null, $args = [])
    {
        // If it's already PDO object, then we simply use it
        if ($dsn instanceof \PDO) {
            $driver = $dsn->getAttribute(\PDO::ATTR_DRIVER_NAME);
            $connectionClass = '\\atk4\\dsql\\Connection';
            $queryClass = null;
            $expressionClass = null;
            switch ($driver) {
                case 'pgsql':
                    $connectionClass = '\\atk4\\dsql\\Connection_PgSQL';
                    $queryClass = 'atk4\dsql\Query_PgSQL';
                    break;
                case 'oci':
                    $connectionClass = '\\atk4\\dsql\\Connection_Oracle';
                    break;
                case 'sqlite':
                    $queryClass = 'atk4\dsql\Query_SQLite';
                    break;
                case 'mysql':
                    $expressionClass = 'atk4\dsql\Expression_MySQL';
                default:
                    // Default, for backwards compatibility
                    $queryClass = 'atk4\dsql\Query_MySQL';
                    break;

            }

            return new $connectionClass(array_merge([
                    'connection'       => $dsn,
                    'query_class'      => $queryClass,
                    'expression_class' => $expressionClass,
                ], $args));
        }

        // If it's some other object, then we simply use it trough proxy connection
        if (is_object($dsn)) {
            return new Connection_Proxy(array_merge([
                    'connection'       => $dsn,
                ], $args));
        }

        // Process DSN string
        $dsn = static::normalizeDSN($dsn, $user, $password);

        // Create driver specific connection
        switch ($dsn['driver']) {
            case 'mysql':
                $c = new static(array_merge([
                    'connection'       => new \PDO($dsn['dsn'], $dsn['user'], $dsn['pass']),
                    'expression_class' => 'atk4\dsql\Expression_MySQL',
                    'query_class'      => 'atk4\dsql\Query_MySQL',
                ], $args));
                break;

            case 'sqlite':
                $c = new static(array_merge([
                    'connection'       => new \PDO($dsn['dsn'], $dsn['user'], $dsn['pass']),
                    'query_class'      => 'atk4\dsql\Query_SQLite',
                ], $args));
                break;

            case 'oci':
                $c = new Connection_Oracle(array_merge([
                    'connection' => new \PDO($dsn['dsn'], $dsn['user'], $dsn['pass']),
                ], $args));
                break;

            case 'oci12':
                $dsn['dsn'] = str_replace('oci12:', 'oci:', $dsn['dsn']);
                $c = new Connection_Oracle12(array_merge([
                    'connection' => new \PDO($dsn['dsn'], $dsn['user'], $dsn['pass']),
                ], $args));
                break;

            case 'pgsql':
                $c = new Connection_PgSQL(array_merge([
                    'connection' => new \PDO($dsn['dsn'], $dsn['user'], $dsn['pass']),
                ], $args));
                break;

            case 'dumper':
                $c = new Connection_Dumper(array_merge([
                    'connection' => static::connect($dsn['rest'], $dsn['user'], $dsn['pass']),
                ], $args));
                break;

            case 'counter':
                $c = new Connection_Counter(array_merge([
                    'connection' => static::connect($dsn['rest'], $dsn['user'], $dsn['pass']),
                ], $args));
                break;

                // let PDO handle the rest
            default:
                $c = new static(array_merge([
                    'connection' => new \PDO($dsn['dsn'], $dsn['user'], $dsn['pass']),
                ], $args));
        }

        return $c;
    }
Connect database.

@param string|\PDO $dsn
@param null|string $user
@param null|string $password
@param array       $args

@return Connection