public function openConnection($name='db_default') {
        foreach ($this->connections as $connection) {
            if($connection['name'] == $name) {
                return $connection['lynk'];
            }
        }
        //Open new connection
        try {
            //Get the configuration of the connection.
            $dbConfig = $this->config->get($name);
            //Create the new connection.
            $connection = new \PDO('mysql:host=' . $dbConfig['host'] .
                                       ';port=' . $dbConfig['port'] .
                                       ';dbname=' . $dbConfig['name'],
                                   $dbConfig['user'],
                                   $dbConfig['pass'],
                                   array(\PDO::MYSQL_ATTR_FOUND_ROWS => true, \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));

            $connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

            $this->connections[] = array('name'=>$name,'lynk'=>$connection);

            return $connection;

        } catch (\Exception $e) {
            throw new ModelException('Error trying to connect to db');
        }
    }
public function openConnection($name='db_default') {
        foreach ($this->connections as $connection) {
            if($connection['name'] == $name) {
                return $connection['lynk'];
            }
        }
        //Open new connection
        try {
            //Get the configuration of the connection.
            $dbConfig = $this->config->get($name);
            //Create the new connection.
            $connection = new \PDO('mysql:host=' . $dbConfig['host'] .
                                       ';port=' . $dbConfig['port'] .
                                       ';dbname=' . $dbConfig['name'],
                                   $dbConfig['user'],
                                   $dbConfig['pass'],
                                   array(\PDO::MYSQL_ATTR_FOUND_ROWS => true, \PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));

            $connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);

            $this->connections[] = array('name'=>$name,'lynk'=>$connection);

            return $connection;

        } catch (\Exception $e) {
            throw new ModelException('Error trying to connect to db');
        }
    }
public function openConnection ( $ name = 'db_default' ) { foreach ( $ this -> connections as $ connection ) { if ( $ connection [ 'name' ] == $ name ) { return $ connection [ 'lynk' ] ; } } //Open new connection try { //Get the configuration of the connection. $ dbConfig = $ this -> config -> get ( $ name ) ; //Create the new connection. $ connection = new \ PDO ( 'mysql:host=' . $ dbConfig [ 'host' ] . ';port=' . $ dbConfig [ 'port' ] . ';dbname=' . $ dbConfig [ 'name' ] , $ dbConfig [ 'user' ] , $ dbConfig [ 'pass' ] , array ( \ PDO :: MYSQL_ATTR_FOUND_ROWS => true , \ PDO :: MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8" ) ) ; $ connection -> setAttribute ( \ PDO :: ATTR_ERRMODE , \ PDO :: ERRMODE_EXCEPTION ) ; $ this -> connections [ ] = array ( 'name' => $ name , 'lynk' => $ connection ) ; return $ connection ; } catch ( \ Exception $ e ) { throw new ModelException ( 'Error trying to connect to db' ) ; } }
Open connection if is not already open.

@param string $name optional parameter if nothing is send it gets
the default connection.

@return \PDO
@throws \ModelException
Open connection if is not already open .