Database.php 1.11 KB
Newer Older
1 2 3
<?php
class Database extends mysqli {
	public function replicaConnect($database) {
Luke081515's avatar
Luke081515 committed
4 5
		$mycnf = parse_ini_file("./replica.my.cnf");
		$cluster = (preg_match('/[-_]p$/', $database)) ? substr($database, 0, -2) : $database;
6 7
		parent::connect($cluster . '.labsdb', $mycnf['user'], $mycnf['password']);
		unset($mycnf);
Luke081515's avatar
Luke081515 committed
8
		if ($this->connect_error) {
9 10 11 12 13
			die( '<p><strong>Database server login failed.</strong> '
			. ' This is probably a temporary problem with the server and will be fixed soon. '
			. ' The server returned error code ' . $this->connect_errno . '.</p>' );
		}
		$res = $this->select_db(str_replace('-', '_', $database));
Luke081515's avatar
Luke081515 committed
14
		if ($res === false) {
15 16 17 18 19 20 21
			die( '<p><strong>Database selection failed.</strong> '
			. ' This is probably a temporary problem with the server and will be fixed soon.</p>' );
		}
	}
	public static function getName($lang, $project, $separator = '-') {
		if ($project == 'wikipedia') {
			$project = 'wiki';
Luke081515's avatar
Luke081515 committed
22
		} else if ($project == 'wikimedia') {
23
			$project = 'wiki';
Luke081515's avatar
Luke081515 committed
24
		} else if ($project == 'wikidata') {
25 26 27 28 29
			$project = 'wiki';
			$lang = 'wikidata';
		}
		return $lang . $project . $separator . 'p';
	}
30
}