public function getDBConnection($dbName = null)
    {
        $rDBName = (!$dbName) ? "Default" : $dbName;
        if (isset($this->_dbConnection[$rDBName])) {
            $db = $this->_dbConnection[$rDBName];
            if (!CLI) {
                return $db;
            }
        }

        $dbInfo = $this->getConfiguration()->getDatabaseInfo($rDBName);

        //require_once 'Zend/Db.php';

        $params = array(
            'host' => $dbInfo["Server"],
            'username' => $dbInfo["User"],
            'password' => $dbInfo["Password"],
            'dbname' => $dbInfo["DBName"],
            'port' => $dbInfo["Port"],
            'charset' => $dbInfo["Charset"]
        );
        if ($dbInfo["Options"]) {
            $options = explode(";", $dbInfo["Options"]);
            foreach ($options as $opt) {
                list($k, $v) = explode("=", $opt);
                $params[$k] = $v;
            }
        }
        foreach ($params as $name => $val) {
            if (empty($val)) {
                unset($params[$name]);
            }
        }
        if (strtoupper($dbInfo["Driver"]) == "PDO_MYSQL") {
            $pdoParams = array(
                \PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
            );
            $params["driver_options"] = $pdoParams;
        }

        $db = \Zend_Db::factory($dbInfo["Driver"], $params);
        $db->setFetchMode(\PDO::FETCH_NUM);

        if (strtoupper($dbInfo["Driver"]) == "PDO_MYSQL" &&
                $dbInfo["Charset"] != "") {
            $db->query("SET NAMES '" . $params['charset'] . "'");
        }
        $this->_dbConnection[$rDBName] = $db;
        return $db;
    }
public function getDBConnection($dbName = null)
    {
        $rDBName = (!$dbName) ? "Default" : $dbName;
        if (isset($this->_dbConnection[$rDBName])) {
            $db = $this->_dbConnection[$rDBName];
            if (!CLI) {
                return $db;
            }
        }

        $dbInfo = $this->getConfiguration()->getDatabaseInfo($rDBName);

        //require_once 'Zend/Db.php';

        $params = array(
            'host' => $dbInfo["Server"],
            'username' => $dbInfo["User"],
            'password' => $dbInfo["Password"],
            'dbname' => $dbInfo["DBName"],
            'port' => $dbInfo["Port"],
            'charset' => $dbInfo["Charset"]
        );
        if ($dbInfo["Options"]) {
            $options = explode(";", $dbInfo["Options"]);
            foreach ($options as $opt) {
                list($k, $v) = explode("=", $opt);
                $params[$k] = $v;
            }
        }
        foreach ($params as $name => $val) {
            if (empty($val)) {
                unset($params[$name]);
            }
        }
        if (strtoupper($dbInfo["Driver"]) == "PDO_MYSQL") {
            $pdoParams = array(
                \PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true
            );
            $params["driver_options"] = $pdoParams;
        }

        $db = \Zend_Db::factory($dbInfo["Driver"], $params);
        $db->setFetchMode(\PDO::FETCH_NUM);

        if (strtoupper($dbInfo["Driver"]) == "PDO_MYSQL" &&
                $dbInfo["Charset"] != "") {
            $db->query("SET NAMES '" . $params['charset'] . "'");
        }
        $this->_dbConnection[$rDBName] = $db;
        return $db;
    }
public function getDBConnection ( $ dbName = null ) { $ rDBName = ( ! $ dbName ) ? "Default" : $ dbName ; if ( isset ( $ this -> _dbConnection [ $ rDBName ] ) ) { $ db = $ this -> _dbConnection [ $ rDBName ] ; if ( ! CLI ) { return $ db ; } } $ dbInfo = $ this -> getConfiguration ( ) -> getDatabaseInfo ( $ rDBName ) ; //require_once 'Zend/Db.php'; $ params = array ( 'host' => $ dbInfo [ "Server" ] , 'username' => $ dbInfo [ "User" ] , 'password' => $ dbInfo [ "Password" ] , 'dbname' => $ dbInfo [ "DBName" ] , 'port' => $ dbInfo [ "Port" ] , 'charset' => $ dbInfo [ "Charset" ] ) ; if ( $ dbInfo [ "Options" ] ) { $ options = explode ( ";" , $ dbInfo [ "Options" ] ) ; foreach ( $ options as $ opt ) { list ( $ k , $ v ) = explode ( "=" , $ opt ) ; $ params [ $ k ] = $ v ; } } foreach ( $ params as $ name => $ val ) { if ( empty ( $ val ) ) { unset ( $ params [ $ name ] ) ; } } if ( strtoupper ( $ dbInfo [ "Driver" ] ) == "PDO_MYSQL" ) { $ pdoParams = array ( \ PDO :: MYSQL_ATTR_USE_BUFFERED_QUERY => true ) ; $ params [ "driver_options" ] = $ pdoParams ; } $ db = \ Zend_Db :: factory ( $ dbInfo [ "Driver" ] , $ params ) ; $ db -> setFetchMode ( \ PDO :: FETCH_NUM ) ; if ( strtoupper ( $ dbInfo [ "Driver" ] ) == "PDO_MYSQL" && $ dbInfo [ "Charset" ] != "" ) { $ db -> query ( "SET NAMES '" . $ params [ 'charset' ] . "'" ) ; } $ this -> _dbConnection [ $ rDBName ] = $ db ; return $ db ; }
Get the database connection object

@param string $dbName    database name declared in config.xml
@return \Zend_Db_Adapter_Abstract
Get the database connection object