Test Setup Failed
Push — master ( d6fde7...1e848b )
by Php Easy Api
04:20
created

Mysql::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
namespace Migratio\Connector;
4
5
use Migratio\GrammarStructure\Mysql\QueryBase;
6
7
class Mysql extends QueryBase
8
{
9
    /**
10
     * @var $instance
0 ignored issues
show
Documentation Bug introduced by
The doc comment $instance at position 0 could not be parsed: Unknown type name '$instance' at position 0 in $instance.
Loading history...
11
     */
12
    private static $instance;
13
14
    /**
15
     * @var $connection
0 ignored issues
show
Documentation Bug introduced by
The doc comment $connection at position 0 could not be parsed: Unknown type name '$connection' at position 0 in $connection.
Loading history...
16
     */
17
    protected $connection;
18
19
    /**
20
     * Mysql constructor.
21
     * @param $config
22
     */
23
    public function __construct($config)
24
    {
25
        if(is_null(self::$instance)){
26
27
            //get pdo dsn
28
            $dsn=''.$config['driver'].':host='.$config['host'].';dbname='.$config['database'].'';
29
            $this->connection = new \PDO($dsn, $config['user'], $config['password']);
30
            $this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
31
32
            self::$instance=true;
33
        }
34
    }
35
36
    /**
37
     * @return \PDO
38
     */
39
    public function getConnection()
40
    {
41
        return $this->connection;
42
    }
43
44
}