Allow setting of alternative MySQL port

This commit is contained in:
Keir Nellyer 2016-08-09 15:37:45 +01:00
parent bc1265a828
commit 84d7838e13

View File

@ -41,13 +41,24 @@
$fullUrl = $parts[1]; $fullUrl = $parts[1];
$urlParts = explode('/', $fullUrl); $urlParts = explode('/', $fullUrl);
$host = $urlParts[0]; $host = $urlParts[0];
$port = 3306;
// check is port has been declared
if (strpos($host, ':') !== false)
{
$hostParts = explode(':', $host);
$host = $hostParts[0];
$port = $hostParts[1];
}
$database = $urlParts[1]; $database = $urlParts[1];
$name = $parts[0]; $name = $parts[0];
$username = $parts[2]; $username = $parts[2];
$password = $parts[3]; $password = $parts[3];
$connection = new mysqli($host, $username, $password, $database); echo $port;
$connection = new mysqli($host, $username, $password, $database, $port);
if ($connection->connect_error) { if ($connection->connect_error) {
die("Connection \"$name\" failed: $connection->connect_error"); die("Connection \"$name\" failed: $connection->connect_error");