Add an ability to use non-default database port

Fixes #40
This commit is contained in:
Dmitriy Simushev 2014-07-11 11:08:44 +00:00
parent 524302fb2e
commit 8a79393989
4 changed files with 13 additions and 2 deletions

View File

@ -5,6 +5,7 @@
# MySQL Database parameters # MySQL Database parameters
database: database:
host: "" host: ""
port: 3306
db: "" db: ""
login: "" login: ""
pass: "" pass: ""

View File

@ -47,6 +47,12 @@ class Database
*/ */
protected $dbHost = ''; protected $dbHost = '';
/**
* Database port
* @var int
*/
protected $dbPort = 0;
/** /**
* Database user's login * Database user's login
* @var string * @var string
@ -132,6 +138,7 @@ class Database
* Create PDO object and store it in the Database object. * Create PDO object and store it in the Database object.
* *
* @param string $host Database host. * @param string $host Database host.
* @param int $port Database port.
* @param string $user Database user name. * @param string $user Database user name.
* @param string $pass Database for user with $name password. * @param string $pass Database for user with $name password.
* @param boolean $use_pconn Control use persistent connection to the * @param boolean $use_pconn Control use persistent connection to the
@ -139,7 +146,7 @@ class Database
* @param string $db Database name. * @param string $db Database name.
* @param string $prefix Database tables prefix * @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 // Check PDO
if (!extension_loaded('PDO')) { if (!extension_loaded('PDO')) {
@ -160,6 +167,7 @@ class Database
// Set database and connection properties // Set database and connection properties
$instance->dbHost = $host; $instance->dbHost = $host;
$instance->dbPort = $port;
$instance->dbLogin = $user; $instance->dbLogin = $user;
$instance->dbPass = $pass; $instance->dbPass = $pass;
$instance->dbName = $db; $instance->dbName = $db;
@ -168,7 +176,7 @@ class Database
// Create PDO object // Create PDO object
$instance->dbh = new \PDO( $instance->dbh = new \PDO(
"mysql:host={$instance->dbHost};dbname={$instance->dbName}", "mysql:host={$instance->dbHost};port={$instance->dbPort};dbname={$instance->dbName}",
$instance->dbLogin, $instance->dbLogin,
$instance->dbPass, $instance->dbPass,
array(\PDO::ATTR_PERSISTENT => $instance->usePersistentConnection) array(\PDO::ATTR_PERSISTENT => $instance->usePersistentConnection)

View File

@ -706,6 +706,7 @@ class Installer
try { try {
Database::initialize( Database::initialize(
$this->configs['database']['host'], $this->configs['database']['host'],
$this->configs['database']['port'],
$this->configs['database']['login'], $this->configs['database']['login'],
$this->configs['database']['pass'], $this->configs['database']['pass'],
$this->configs['database']['use_persistent_connection'], $this->configs['database']['use_persistent_connection'],

View File

@ -76,6 +76,7 @@ if (!installation_in_progress()) {
// Initialize the database // Initialize the database
\Mibew\Database::initialize( \Mibew\Database::initialize(
$configs['database']['host'], $configs['database']['host'],
$configs['database']['port'],
$configs['database']['login'], $configs['database']['login'],
$configs['database']['pass'], $configs['database']['pass'],
$configs['database']['use_persistent_connection'], $configs['database']['use_persistent_connection'],