/**
  * Enable the query cache
  * 
  * This does not take precedence over the Elgg_Database_Config setting.
  * 
  * @return void
  */
 public function enableQueryCache()
 {
     if ($this->config->isQueryCacheEnabled() && $this->queryCache === null) {
         // @todo if we keep this cache, expose the size as a config parameter
         $this->queryCache = new Elgg_Cache_LRUCache($this->queryCacheSize);
     }
 }
Example #2
0
 /**
  * Establish a connection to the database server
  *
  * Connect to the database server and use the Elgg database for a particular database link
  *
  * @param string $dblinkname The type of database connection. Used to identify the
  * resource: "read", "write", or "readwrite".
  *
  * @return void
  * @throws DatabaseException
  */
 public function establishLink($dblinkname = "readwrite")
 {
     global $CONFIG;
     $conf = $this->config->getConnectionConfig($dblinkname);
     // Connect to database
     if (!($this->dbLinks[$dblinkname] = mysql_connect($conf['host'], $conf['user'], $conf['password'], true))) {
         $msg = "Elgg couldn't connect to the database using the given credentials. Check the settings file.";
         throw new DatabaseException($msg);
     }
     if (!mysql_select_db($conf['database'], $this->dbLinks[$dblinkname])) {
         $msg = "Elgg couldn't select the database '{$conf['database']}'. Please check that the database is created and you have access to it.";
         throw new DatabaseException($msg);
     }
     // Set DB for UTF8
     mysql_query("SET NAMES utf8");
 }
 public function testGetConnectionConfigWithMultipleReadOldStyle()
 {
     $ans = array(0 => array('host' => 0, 'user' => 'user0', 'password' => 'xxxx0', 'database' => 'elgg0'), 1 => array('host' => 1, 'user' => 'user1', 'password' => 'xxxx1', 'database' => 'elgg1'));
     $CONFIG = new stdClass();
     $CONFIG->db['read'][0] = new stdClass();
     $CONFIG->db['read'][0]->dbhost = $ans[0]['host'];
     $CONFIG->db['read'][0]->dbuser = $ans[0]['user'];
     $CONFIG->db['read'][0]->dbpass = $ans[0]['password'];
     $CONFIG->db['read'][0]->dbname = $ans[0]['database'];
     $CONFIG->db['read'][1] = new stdClass();
     $CONFIG->db['read'][1]->dbhost = $ans[1]['host'];
     $CONFIG->db['read'][1]->dbuser = $ans[1]['user'];
     $CONFIG->db['read'][1]->dbpass = $ans[1]['password'];
     $CONFIG->db['read'][1]->dbname = $ans[1]['database'];
     $conf = new Elgg_Database_Config($CONFIG);
     $connConf = $conf->getConnectionConfig(Elgg_Database_Config::READ);
     $this->assertEquals($ans[$connConf['host']], $connConf);
 }