Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/milux/spdo/SPDOConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -60,4 +67,4 @@ public function newSPDOStatement($pdoStatement) {
return new SPDOStatement($pdoStatement);
}

}
}
9 changes: 7 additions & 2 deletions src/milux/spdo/SPDOConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 + [
Expand Down Expand Up @@ -417,4 +422,4 @@ public function lastInsertId($insertIdName = null) {
return $this->pdo->lastInsertId($insertIdName);
}

}
}