From 8a7939398923ab648e9336da1b0f8492e7152ce3 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Fri, 11 Jul 2014 11:08:44 +0000 Subject: [PATCH] Add an ability to use non-default database port Fixes #40 --- src/mibew/configs/default_config.yml | 1 + src/mibew/libs/classes/Mibew/Database.php | 12 ++++++++++-- src/mibew/libs/classes/Mibew/Installer.php | 1 + src/mibew/libs/init.php | 1 + 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/mibew/configs/default_config.yml b/src/mibew/configs/default_config.yml index 7b47db2a..b6597b35 100644 --- a/src/mibew/configs/default_config.yml +++ b/src/mibew/configs/default_config.yml @@ -5,6 +5,7 @@ # MySQL Database parameters database: host: "" + port: 3306 db: "" login: "" pass: "" diff --git a/src/mibew/libs/classes/Mibew/Database.php b/src/mibew/libs/classes/Mibew/Database.php index 6b86f090..d6931551 100644 --- a/src/mibew/libs/classes/Mibew/Database.php +++ b/src/mibew/libs/classes/Mibew/Database.php @@ -47,6 +47,12 @@ class Database */ protected $dbHost = ''; + /** + * Database port + * @var int + */ + protected $dbPort = 0; + /** * Database user's login * @var string @@ -132,6 +138,7 @@ class Database * Create PDO object and store it in the Database object. * * @param string $host Database host. + * @param int $port Database port. * @param string $user Database user name. * @param string $pass Database for user with $name password. * @param boolean $use_pconn Control use persistent connection to the @@ -139,7 +146,7 @@ class Database * @param string $db Database name. * @param string $prefix Database tables prefix */ - public static function initialize($host, $user, $pass, $use_pconn, $db, $prefix) + public static function initialize($host, $port, $user, $pass, $use_pconn, $db, $prefix) { // Check PDO if (!extension_loaded('PDO')) { @@ -160,6 +167,7 @@ class Database // Set database and connection properties $instance->dbHost = $host; + $instance->dbPort = $port; $instance->dbLogin = $user; $instance->dbPass = $pass; $instance->dbName = $db; @@ -168,7 +176,7 @@ class Database // Create PDO object $instance->dbh = new \PDO( - "mysql:host={$instance->dbHost};dbname={$instance->dbName}", + "mysql:host={$instance->dbHost};port={$instance->dbPort};dbname={$instance->dbName}", $instance->dbLogin, $instance->dbPass, array(\PDO::ATTR_PERSISTENT => $instance->usePersistentConnection) diff --git a/src/mibew/libs/classes/Mibew/Installer.php b/src/mibew/libs/classes/Mibew/Installer.php index 954f365d..e9e0b483 100644 --- a/src/mibew/libs/classes/Mibew/Installer.php +++ b/src/mibew/libs/classes/Mibew/Installer.php @@ -706,6 +706,7 @@ class Installer try { Database::initialize( $this->configs['database']['host'], + $this->configs['database']['port'], $this->configs['database']['login'], $this->configs['database']['pass'], $this->configs['database']['use_persistent_connection'], diff --git a/src/mibew/libs/init.php b/src/mibew/libs/init.php index 3061126f..56e757ec 100644 --- a/src/mibew/libs/init.php +++ b/src/mibew/libs/init.php @@ -76,6 +76,7 @@ if (!installation_in_progress()) { // Initialize the database \Mibew\Database::initialize( $configs['database']['host'], + $configs['database']['port'], $configs['database']['login'], $configs['database']['pass'], $configs['database']['use_persistent_connection'],