<commit_before><?php
class Vps_Dao
{
    private $_config;
    private $_tables = array();
    private $_db = array();
    private $_pageData = array();

    public function __construct(array $config = null)
    {
        if (is_null($config)) {
	    if (file_exists('application/config.db.ini')) {
                $config = new Zend_Config_Ini('application/config.db.ini', 'database');
                $config = $config->toArray();
	    } else {
	        $config = array();
	    }
        }
        $this->_config = $config;
    }

    public static function getTable($tablename, $config = array())
    {
        static $tables;
        if (!isset($tables[$tablename])) {
            $tables[$tablename] = new $tablename($config);
        }
        return $tables[$tablename];
    }

    public function getDbConfig($db = 'web')
    {
        if (!isset($this->_config[$db])) {
            throw new Vps_Dao_Exception("Connection \"$db\" in config.db.ini not found.
                    Please add $db.host, $db.username, $db.password and $db.dbname under the sction [database].");
        }
        $dbConfig = $this->_config[$db];
        if (!isset($dbConfig['username']) && isset($dbConfig['user'])) $dbConfig['username'] = $dbConfig['user'];
        if (!isset($dbConfig['password']) && isset($dbConfig['pass'])) $dbConfig['password'] = $dbConfig['pass'];
        if (!isset($dbConfig['dbname']) && isset($dbConfig['name'])) $dbConfig['dbname'] = $dbConfig['name'];
        return $dbConfig;
    }

    public function getDb($db = 'web')
    {
        if (!isset($this->_db[$db])) {
            $dbConfig = $this->getDbConfig($db);
            $this->_db[$db] = Zend_Db::factory('PDO_MYSQL', $dbConfig);
            $this->_db[$db]->query('SET names UTF8');

            /**
             * lc_time_names wird hier nicht gesetzt weil man für trlVps
             * momentan das userModel benötigt und das gibts ohne DB
             * Verbindung nicht -> Endlosschleifen gefahr.
             * lc_time_names wurde früher vermutlich im TreeCache noch benötigt
             * (z.B. bei den News Month), aber das macht jetzt das PHP, dehalb
             * ist es nicht mehr nötig dies zu setzen.
             */
//             $this->_db[$db]->query("SET lc_time_names = '".trlVps('en_US')."'");


            if (Zend_Registry::get('config')->debug->querylog) {
                $profiler = new Vps_Db_Profiler(true);
                $this->_db[$db]->setProfiler($profiler);
            } else if (Zend_Registry::get('config')->debug->benchmark || Zend_Registry::get('config')->debug->benchmarkLog) {
                $profiler = new Vps_Db_Profiler_Count(true);
                $this->_db[$db]->setProfiler($profiler);
            }
        }<commit_msg>persistente db-verbindung aufbauen<commit_after><?php
class Vps_Dao
{
    private $_config;
    private $_tables = array();
    private $_db = array();
    private $_pageData = array();

    public function __construct(array $config = null)
    {
        if (is_null($config)) {
	    if (file_exists('application/config.db.ini')) {
                $config = new Zend_Config_Ini('application/config.db.ini', 'database');
                $config = $config->toArray();
	    } else {
	        $config = array();
	    }
        }
        $this->_config = $config;
    }

    public static function getTable($tablename, $config = array())
    {
        static $tables;
        if (!isset($tables[$tablename])) {
            $tables[$tablename] = new $tablename($config);
        }
        return $tables[$tablename];
    }

    public function getDbConfig($db = 'web')
    {
        if (!isset($this->_config[$db])) {
            throw new Vps_Dao_Exception("Connection \"$db\" in config.db.ini not found.
                    Please add $db.host, $db.username, $db.password and $db.dbname under the sction [database].");
        }
        $dbConfig = $this->_config[$db];
        if (!isset($dbConfig['username']) && isset($dbConfig['user'])) $dbConfig['username'] = $dbConfig['user'];
        if (!isset($dbConfig['password']) && isset($dbConfig['pass'])) $dbConfig['password'] = $dbConfig['pass'];
        if (!isset($dbConfig['dbname']) && isset($dbConfig['name'])) $dbConfig['dbname'] = $dbConfig['name'];
        $dbConfig['persistent'] = true;
        return $dbConfig;
    }

    public function getDb($db = 'web')
    {
        if (!isset($this->_db[$db])) {
            $dbConfig = $this->getDbConfig($db);
            $this->_db[$db] = Zend_Db::factory('PDO_MYSQL', $dbConfig);
            $this->_db[$db]->query('SET names UTF8');

            /**
             * lc_time_names wird hier nicht gesetzt weil man für trlVps
             * momentan das userModel benötigt und das gibts ohne DB
             * Verbindung nicht -> Endlosschleifen gefahr.
             * lc_time_names wurde früher vermutlich im TreeCache noch benötigt
             * (z.B. bei den News Month), aber das macht jetzt das PHP, dehalb
             * ist es nicht mehr nötig dies zu setzen.
             */
//             $this->_db[$db]->query("SET lc_time_names = '".trlVps('en_US')."'");


            if (Zend_Registry::get('config')->debug->querylog) {
                $profiler = new Vps_Db_Profiler(true);
                $this->_db[$db]->setProfiler($profiler);
            } else if (Zend_Registry::get('config')->debug->benchmark || Zend_Registry::get('config')->debug->benchmarkLog) {
                $profiler = new Vps_Db_Profiler_Count(true);
                $this->_db[$db]->setProfiler($profiler);
            }
        }
{'fraction_non_alphanumeric': 0.16274474582360338, 'fraction_numerical': 0.00035925992455541585, 'mean_word_length': 2.340131973605279, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3973604', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1678, 'n_words': 352}