0

I am new in php and doing a login/register page in localhost using xampp on mac. I am having a trouble with this error:

Warning: mysqli_connect(): (HY000/2002): Connection refused in /opt/lampp/htdocs/website/includes/dbh.inc.php on line 9 Connection failed: Connection refused

I have tried changing the code but it continuously adding more problems.

This is my code:

<?php

$servername = "192.168.64.2:8080";
$dBUsername = "root";
$dBPassword = "";
$dBName = "loginsystem";

$conn = mysqli_connect($servername, $dBUsername, $dBPassword, $dBName);

if (!$conn) {
    die("Connection failed: ".mysqli_connect_error());
}   

How can I eliminate this error?

halfer
  • 19,824
  • 17
  • 99
  • 186
brandxkevin02
  • 13
  • 1
  • 3

1 Answers1

-1

If you want to connect to other port than the default one, add the port argument when you establish the connection, not define it within the server name.

$servername = "192.168.64.2";
$dBUsername = "root";
$dBPassword = "";
$dBName = "loginsystem";
$dbPort = "8080";

$conn = mysqli_connect($servername, $dBUsername, $dBPassword, $dBName, $dbPort);

if (!$conn) {
    die("Connection failed: ".mysqli_connect_error());
}  

Another thing is to make sure you have the right port of MySQL service, port 8080 is commonly picked as the alternative for port 80 to handle HTTP request. Check your XAMPP configuration to find out which port is used for MySQL.

catcon
  • 1,295
  • 1
  • 9
  • 18