Skip to content

Commit c9a23eb

Browse files
committed
Added port to pdo connection string..
Use host:port notation on constructor, or directly access class atributes. Some coded borrowed from: https://github.com/web2nr/mysqldump-php/commit/f635699f6ad7f56bba3963567718d2eaddf27f45
1 parent 8e5c9df commit c9a23eb

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/Ifsnop/Mysqldump/Mysqldump.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Mysqldump
4747

4848
// This can be set both on constructor or manually
4949
public $host;
50+
public $port;
5051
public $user;
5152
public $pass;
5253
public $db;
@@ -120,7 +121,16 @@ public function __construct(
120121
$this->db = $db;
121122
$this->user = $user;
122123
$this->pass = $pass;
123-
$this->host = $host;
124+
125+
$colonPos = strpos($host, ':');
126+
if (false !== $colonPos) {
127+
$this->port = substr($host, $colonPos + 1);
128+
$this->host = substr($host, 0, $colonPos);
129+
} else {
130+
$this->port = null;
131+
$this->host = $host;
132+
}
133+
124134
$this->dbType = strtolower($type);
125135
$this->pdoSettings = self::array_replace_recursive($pdoSettingsDefault, $pdoSettings);
126136
$this->dumpSettings = self::array_replace_recursive($dumpSettingsDefault, $dumpSettings);
@@ -179,9 +189,12 @@ private function connect()
179189
case 'mysql':
180190
case 'pgsql':
181191
case 'dblib':
192+
$dsn = $this->dbType .
193+
":host=" . $this->host .
194+
(isset($this->port) ? ";port=" . $this->port : "") .
195+
";dbname=" . $this->db;
182196
$this->dbHandler = new PDO(
183-
$this->dbType . ":host=" .
184-
$this->host . ";dbname=" . $this->db,
197+
$dsn,
185198
$this->user,
186199
$this->pass,
187200
$this->pdoSettings

tests/test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"test001",
3434
"travis",
3535
"",
36-
"localhost",
36+
"localhost:3306",
3737
"mysql",
3838
$dumpSettings);
3939

0 commit comments

Comments
 (0)