Jump to content

puzzles

Members
  • Posts

    5
  • Joined

Community Answers

  1. puzzles's post in How to add a second login server to Flux? was marked as the answer   
    I solved this issue partially. I created a new value for the connect function to specify which server to connect to. This function works only when a user is logged out (useful for quick loading databases/who's online/rankings). It will not work for logged in characters because their connection is called at /lib/Flux/SessionData.php:355 which applies to all queries. This means when set to a replicated server it breaks gender changes/preferences/slot changes etc. If anyone knows a solution to this issue, please let me know.   Replace the connect, getConnection and getStatement functions at lib\Flux\connection.php with these:   
    private function connect(Flux_Config $dbConfig, $altServer)     {         $dsn = 'mysql:';                  // Differentiate between a socket-type connection or an ip:port         // connection.         if ($sock=$dbConfig->getSocket()) {             $dsn .= "unix_socket=$sock";         }         else {             if(isset($altServer)) $dsn .= 'host='.Flux::config($altServer.'.Hostname');             else $dsn .= 'host='.$dbConfig->getHostname();             if ($port=$dbConfig->getPort()) {                 $dsn .= ";port=$port";             }         }                  // May or may not have a database name specified.         if ($dbName=$dbConfig->getDatabase()) {             if(isset($altServer)) $dsn .= ";dbname=".Flux::config($altServer.'.Database');             else $dsn .= ";dbname=$dbName";         }                  $persistent = array(PDO::ATTR_PERSISTENT => (bool)$dbConfig->getPersistent());         if(isset($altServer)) return new PDO($dsn, Flux::config($altServer.'.Username'), Flux::config($altServer.'.Password'), $persistent);         else return new PDO($dsn, $dbConfig->getUsername(), $dbConfig->getPassword(), $persistent);     }     
    private function getConnection($altServer)     {         if (!$this->pdoMain) {             // Establish connection for main databases.             $pdoMain       = $this->connect($this->dbConfig, $altServer);             $this->pdoMain = $pdoMain;                          if ($encoding=$this->dbConfig->getEncoding()) {                 $sth = $this->getStatement("SET NAMES ?");                 $sth->execute(array($encoding));             }             if ($timezone=$this->dbConfig->getTimezone()) {                 $sth = $this->getStatement("SET time_zone = ?");                 $sth->execute(array($timezone));             }         }         return $this->pdoMain;     }    public function getStatement($statement, $options = array(), $altServer=null)     {         $dbh = $this->getConnection($altServer);         if(isset($options)) $sth = $dbh->prepare($statement, $options);         else $sth = $dbh->prepare($statement);         @$sth->setFetchMode(PDO::FETCH_CLASS, 'Flux_DataObject', array(null, array('dbconfig' => $this->dbConfig)));                  if ($sth) {             return new Flux_Connection_Statement($sth);         }         else {             return false;         }     } Add the following to config\application.php:     'MyServer' => array(         'Hostname'        => '127.0.0.1',         'Username'        => 'username',         'Password'        => 'password',         'Database'        => 'database'     ),      Use this new function for the places you'd like to change servers: getStatement($sql,null,'MyServer');   The item and monster database connections are both made at /lib/Flux/TemporaryTable.php:241
×
×
  • Create New...