protected function getShardLink($shardID, $forWriting = false) { if (isset($this->links[$shardID])) { return $this->links[$shardID]; } $shardInfo = Zotero_Shards::getShardInfo($shardID); if (!$shardInfo) { throw new Exception("Invalid shard {$shardID}"); } if ($shardInfo['state'] == 'down') { throw new Exception("Shard {$shardID} is down", Z_ERROR_SHARD_UNAVAILABLE); } else { if ($shardInfo['state'] == 'readonly') { if ($forWriting) { throw new Exception("Cannot write to read-only shard {$shardID}", Z_ERROR_SHARD_READ_ONLY); } } } $auth = Zotero_DBConnectAuth('shard'); $config = array('host' => $shardInfo['address'], 'port' => $shardInfo['port'], 'username' => $auth['user'], 'password' => $auth['pass'], 'dbname' => $shardInfo['db'], 'charset' => 'utf8'); // For admin, use user/pass from master if (get_called_class() == 'Zotero_Admin_DB') { $auth = Zotero_DBConnectAuth($this->db); $config['username'] = $auth['user']; $config['password'] = $auth['pass']; } $this->links[$shardID] = new Zend_Db_Adapter_Mysqli($config); return $this->links[$shardID]; }
protected function getShardLink($shardID, $forWriting = false) { // TEMP if (get_called_class() == 'Zotero_FullText_DB') { $linkID = "FT" . $shardID; } else { $linkID = $shardID; } if (isset($this->links[$linkID])) { return $this->links[$linkID]; } $shardInfo = Zotero_Shards::getShardInfo($shardID); if (!$shardInfo) { throw new Exception("Invalid shard {$shardID}"); } if ($shardInfo['state'] == 'down') { throw new Exception("Shard {$shardID} is down", Z_ERROR_SHARD_UNAVAILABLE); } else { if ($shardInfo['state'] == 'readonly') { if ($forWriting && get_called_class() != 'Zotero_Admin_DB') { throw new Exception("Cannot write to read-only shard {$shardID}", Z_ERROR_SHARD_READ_ONLY); } } } $auth = Zotero_DBConnectAuth('shard'); $config = array('host' => $shardInfo['address'], 'port' => $shardInfo['port'], 'username' => $auth['user'], 'password' => $auth['pass'], 'dbname' => $shardInfo['db'], 'charset' => !empty($auth['charset']) ? $auth['charset'] : 'utf8', 'driver_options' => array("MYSQLI_OPT_CONNECT_TIMEOUT" => 5)); // TEMP: For now, use separate host if (get_called_class() == 'Zotero_FullText_DB') { $auth = Zotero_DBConnectAuth('fulltext'); $config['host'] = $auth['host']; $config['port'] = $auth['port']; } else { if (get_called_class() == 'Zotero_Admin_DB') { $auth = Zotero_DBConnectAuth($this->db); $config['username'] = $auth['user']; $config['password'] = $auth['pass']; } } $this->links[$linkID] = new Zend_Db_Adapter_Mysqli($config); $conn = $this->links[$linkID]->getConnection(); $conn->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5); // If profile was previously enabled, enable it for this link if ($this->profilerEnabled) { $this->links[$linkID]->getProfiler()->setEnabled(true); } return $this->links[$linkID]; }
private function getLinkFromConnectionInfo($connInfo) { $auth = Zotero_DBConnectAuth('shard'); $config = array('host' => $connInfo['address'], 'port' => $connInfo['port'], 'username' => $auth['user'], 'password' => $auth['pass'], 'dbname' => $connInfo['db'], 'charset' => !empty($auth['charset']) ? $auth['charset'] : 'utf8', 'driver_options' => array("MYSQLI_OPT_CONNECT_TIMEOUT" => 5)); // TEMP: For now, use separate host if (get_called_class() == 'Zotero_FullText_DB') { $auth = Zotero_DBConnectAuth('fulltext'); $config['host'] = $auth['host']; $config['port'] = $auth['port']; } else { if (get_called_class() == 'Zotero_Admin_DB') { $auth = Zotero_DBConnectAuth($this->db); $config['username'] = $auth['user']; $config['password'] = $auth['pass']; } } $link = new Zend_Db_Adapter_Mysqli($config); // If profile was previously enabled, enable it for this link if ($this->profilerEnabled) { $link->getProfiler()->setEnabled(true); } return $link; }