Просмотр исходного кода

Merge pull request #1244 from Alkarex/MySQL-port

Support custom MySQL ports
Alexandre Alapetite 9 лет назад
Родитель
Сommit
c3589cac2d
3 измененных файлов с 8 добавлено и 2 удалено
  1. 2 0
      CHANGELOG.md
  2. 1 1
      app/install.php
  3. 5 1
      lib/Minz/ModelPdo.php

+ 2 - 0
CHANGELOG.md

@@ -2,6 +2,8 @@
 
 ## 2016-XX-XX FreshRSS 1.6.0-dev
 
+* Features
+	* Support custom ports `localhost:3306` for database servers [#1241](https://github.com/FreshRSS/FreshRSS/issues/1241)
 * Security
 	* Prevent `<a target="_blank">` attacks with `window.opener` [#1245](https://github.com/FreshRSS/FreshRSS/issues/1245)
 * UI

+ 1 - 1
app/install.php

@@ -716,7 +716,7 @@ function printStep3() {
 		<div class="form-group">
 			<label class="group-name" for="host"><?php echo _t('install.bdd.host'); ?></label>
 			<div class="group-controls">
-				<input type="text" id="host" name="host" pattern="[0-9A-Za-z_.-]{1,64}" value="<?php echo isset($_SESSION['bd_host']) ? $_SESSION['bd_host'] : $system_default_config->db['host']; ?>" tabindex="2" />
+				<input type="text" id="host" name="host" pattern="[0-9A-Za-z_.-]{1,64}(:[0-9]{2,5})?" value="<?php echo isset($_SESSION['bd_host']) ? $_SESSION['bd_host'] : $system_default_config->db['host']; ?>" tabindex="2" />
 			</div>
 		</div>
 

+ 5 - 1
lib/Minz/ModelPdo.php

@@ -53,13 +53,17 @@ class Minz_ModelPdo {
 		self::$sharedCurrentUser = $currentUser;
 
 		$driver_options = isset($conf->db['pdo_options']) && is_array($conf->db['pdo_options']) ? $conf->db['pdo_options'] : array();
+		$dbServer = parse_url('db://' . $db['host']);
 
 		try {
 			$type = $db['type'];
 			if ($type === 'mysql') {
-				$string = 'mysql:host=' . $db['host']
+				$string = 'mysql:host=' . $dbServer['host']
 				        . ';dbname=' . $db['base']
 				        . ';charset=utf8mb4';
+				if (!empty($dbServer['port'])) {
+					$string .= ';port=' . $dbServer['port'];
+				}
 				$driver_options[PDO::MYSQL_ATTR_INIT_COMMAND] = 'SET NAMES utf8mb4';
 				$this->prefix = $db['prefix'] . $currentUser . '_';
 			} elseif ($type === 'sqlite') {