diff --git a/bin/prepare.php b/bin/prepare.php index ae29f124f..d6df8f690 100644 --- a/bin/prepare.php +++ b/bin/prepare.php @@ -17,9 +17,11 @@ $host = $config['db']['host']; $dbname = $config['db']['name']; $user = $config['db']['user']; $password = $config['db']['password']; +$port = $config['db']['port']; + echo sprintf("Connecting to database %s@%s/%s", $user, $host, $dbname) . PHP_EOL; -$dbh = new PDO($type . ':host=' . $host, $user, $password, array( +$dbh = new PDO($type . ':host=' . $host . ';port=' . $port, $user, $password, array( PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, diff --git a/src/bb-config-heroku.php b/src/bb-config-heroku.php index a37ba81d7..7de211640 100755 --- a/src/bb-config-heroku.php +++ b/src/bb-config-heroku.php @@ -94,6 +94,11 @@ return array( * Database password */ 'password' =>getenv('BB_DB_PASSWORD'), + + /** + * Database port + */ + 'port' =>getenv('BB_DB_PORT'), ), 'twig' => array( diff --git a/src/bb-config-sample.php b/src/bb-config-sample.php index f39b6a372..54acad202 100755 --- a/src/bb-config-sample.php +++ b/src/bb-config-sample.php @@ -94,6 +94,11 @@ return array( * Database password */ 'password' =>'foo', + + /** + * Database Port + */ + 'port' =>'3306', ), 'twig' => array( diff --git a/src/bb-di.php b/src/bb-di.php index 7f921430b..c7a98d227 100644 --- a/src/bb-di.php +++ b/src/bb-di.php @@ -47,7 +47,7 @@ $di['crypt'] = function() use ($di) { $di['pdo'] = function() use ($di) { $c = $di['config']['db']; - $pdo = new PDO($c['type'].':host='.$c['host'].';dbname='.$c['name'], + $pdo = new PDO($c['type'].':host='.$c['host'].';port='.$c['port'].';dbname='.$c['name'], $c['user'], $c['password'], array( diff --git a/src/install/index.php b/src/install/index.php index cb4c77dce..abfab0f87 100644 --- a/src/install/index.php +++ b/src/install/index.php @@ -64,13 +64,15 @@ final class Box_Installer $host = $_POST['db_host']; $pass = $_POST['db_pass']; $name = $_POST['db_name']; - if (!$this->canConnectToDatabase($host, $name, $user, $pass)) { + $port = $_POST['db_port']; + if (!$this->canConnectToDatabase($host, $name, $user, $pass, $port)) { print 'Could not connect to database. Please check database details.'; } else { $this->session->set('db_host', $host); $this->session->set('db_name', $name); $this->session->set('db_user', $user); $this->session->set('db_pass', $pass); + $this->session->set('db_port', $port); print 'ok'; } @@ -83,13 +85,15 @@ final class Box_Installer $host = $_POST['db_host']; $pass = $_POST['db_pass']; $name = $_POST['db_name']; - if (!$this->canConnectToDatabase($host, $name, $user, $pass)) { + $port = $_POST['db_port']; + if (!$this->canConnectToDatabase($host, $name, $user, $pass, $port)) { throw new Exception('Could not connect to database or database does not exist'); } else { $this->session->set('db_host', $host); $this->session->set('db_name', $name); $this->session->set('db_user', $user); $this->session->set('db_pass', $pass); + $this->session->set('db_port', $port); } // admin config @@ -146,6 +150,7 @@ final class Box_Installer 'db_name' => $this->session->get('db_name'), 'db_user' => $this->session->get('db_user'), 'db_pass' => $this->session->get('db_pass'), + 'db_port' => $this->session->get('db_port'), 'admin_email' => $this->session->get('admin_email'), 'admin_pass' => $this->session->get('admin_pass'), @@ -195,9 +200,9 @@ final class Box_Installer return file_get_contents($path); } - private function canConnectToDatabase($host, $db, $user, $pass) + private function canConnectToDatabase($host, $db, $user, $pass, $port) { - $con = new mysqli($host, $user, $pass, $db); + $con = new mysqli($host, $user, $pass, $db, $port); if ($con->connect_error) { return false; } @@ -242,7 +247,7 @@ final class Box_Installer $this->_isValidInstallData($ns); $this->_createConfigurationFile($ns); - $link = new mysqli($ns->get('db_host'), $ns->get('db_user'), $ns->get('db_pass'), $ns->get('db_name')); + $link = new mysqli($ns->get('db_host'), $ns->get('db_user'), $ns->get('db_pass'), $ns->get('db_name'), $ns->get('db_port')); if ($link->connect_error) { throw new Exception("Connect Error (" . $link->connect_errno . ") " . $link->connect_error); @@ -353,6 +358,7 @@ final class Box_Installer 'name' => $ns->get('db_name'), 'user' => $ns->get('db_user'), 'password' => $ns->get('db_pass'), + 'port' => $ns->get('db_port'), ], 'twig' => [ @@ -394,6 +400,7 @@ final class Box_Installer $output .= sprintf($f, 'BB_DB_USER', $ns->get('db_user')); $output .= sprintf($f, 'BB_DB_PASSWORD', $ns->get('db_pass')); $output .= sprintf($f, 'BB_DB_HOST', $ns->get('db_host')); + $output .= sprintf($f, 'BB_DB_PORT', $ns->get('db_port')); $output .= sprintf($f, 'BB_DB_TYPE', 'mysql'); $output .= sprintf($cf, 'Live site URL with trailing slash'); @@ -425,7 +432,7 @@ final class Box_Installer private function _isValidInstallData($ns) { - if (!$this->canConnectToDatabase($ns->get('db_host'), $ns->get('db_name'), $ns->get('db_user'), $ns->get('db_pass'))) { + if (!$this->canConnectToDatabase($ns->get('db_host'), $ns->get('db_name'), $ns->get('db_user'), $ns->get('db_pass'), $ns->get('db_port'))) { throw new Exception('Can not connect to database'); } diff --git a/src/install/install.phtml b/src/install/install.phtml index 4ec4642d4..f4d368779 100644 --- a/src/install/install.phtml +++ b/src/install/install.phtml @@ -156,6 +156,13 @@
+