Bluz\Db\Db::connect PHP Method

connect() public method

Connect to Db
public connect ( ) : Db
return Db
    public function connect()
    {
        if (empty($this->handler)) {
            try {
                $this->checkConnect();
                $this->log("Connect to " . $this->connect['host']);
                $this->handler = new \PDO($this->connect['type'] . ":host=" . $this->connect['host'] . ";dbname=" . $this->connect['name'], $this->connect['user'], $this->connect['pass'], $this->connect['options']);
                foreach ($this->attributes as $attribute => $value) {
                    $this->handler->setAttribute($attribute, $value);
                }
                $this->ok();
            } catch (\Exception $e) {
                throw new DbException('Attempt connection to database is failed: ' . $e->getMessage());
            }
        }
        return $this;
    }

Usage Example

コード例 #1
0
ファイル: DbTest.php プロジェクト: dezvell/mm.local
 /**
  * Initial Db with configuration
  */
 public function testCheckConnect()
 {
     $this->db->connect();
     $this->assertInstanceOf('\\Pdo', $this->db->handler());
 }