diff --git a/src/milux/spdo/SPDOConfig.php b/src/milux/spdo/SPDOConfig.php index c8d2388..a3e0440 100644 --- a/src/milux/spdo/SPDOConfig.php +++ b/src/milux/spdo/SPDOConfig.php @@ -16,6 +16,13 @@ abstract class SPDOConfig { */ public abstract function getHost(); + /** + * @return string|null port of the database or null for the default + */ + public function getPort() { + return null; + } + /** * @return string username for login */ @@ -60,4 +67,4 @@ public function newSPDOStatement($pdoStatement) { return new SPDOStatement($pdoStatement); } -} \ No newline at end of file +} diff --git a/src/milux/spdo/SPDOConnection.php b/src/milux/spdo/SPDOConnection.php index f4c7a69..692b2c6 100644 --- a/src/milux/spdo/SPDOConnection.php +++ b/src/milux/spdo/SPDOConnection.php @@ -56,8 +56,13 @@ public static function getTypes(array $values) { public function __construct(SPDOConfig $configObject, array $options = []) { $this->configObject = $configObject; //initialize internal PDO object + $dsn = 'mysql:host=' . $configObject->getHost() . ';dbname=' . $configObject->getSchema(); + $port = $configObject->getPort(); + if ($port) { + $dsn .= ";port=${port}"; + } $this->pdo = new \PDO( - 'mysql:host=' . $configObject->getHost() . ';dbname=' . $configObject->getSchema(), + $dsn, $configObject->getUser(), $configObject->getPassword(), $options + [ @@ -417,4 +422,4 @@ public function lastInsertId($insertIdName = null) { return $this->pdo->lastInsertId($insertIdName); } -} \ No newline at end of file +}