diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index 53e0fdb52..a13152b5e 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -177,7 +177,7 @@ function attach(string $server, string $username, string $password): string { } list($host, $port) = host_port($server); return $this->dsn( - "mysql:charset=utf8;host=$host" . ($port ? (is_numeric($port) ? ";port=" : ";unix_socket=") . $port : ""), + "mysql:charset=utf8".(!empty($host) ? ";host=$host" : '') . ($port ? (is_numeric($port) ? ";port=" : ";unix_socket=") . $port : ""), $username, $password, $options diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index 9cc189e01..d418afb3f 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -839,7 +839,7 @@ function is_shortable(array $field): bool { function host_port(string $server) { return (preg_match('~^(\[(.+)]|([^:]+)):([^:]+)$~', $server, $match) // [a:b] - IPv6 ? array($match[2] . $match[3], $match[4]) - : array($server, '') + : (preg_match('~^(\[(.+)]|([^:]+))$~', $server, $match) ? array($match[2] . $match[3], '') : explode(':', $server, 2)) // Match IPv6 or hostname without port, else split by first colon ); }