Home » Php » php – Connect Error(2002)Connection refused (Heroku)

php – Connect Error(2002)Connection refused (Heroku)

Posted by: admin February 25, 2020 Leave a comment


I have been trying to connect to my database (I used Xampp) and made a PHP trying to link the file to the “users” database that I made. There is an issue as whenever I click the “Register” button it has an error saying “Connect Error(2002)Connection refused.” Any help would be appreciated!

PHP code


$name = $_POST['name'];
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];
$phone = $_POST['phone'];

if (!empty($name) || !empty($username) || !empty($password) || !empty($email) || !empty($phone)) {

    $host = "localhost:80";
    $dbUsername = "root";
    $dbPassword = "";
    $dbname = "pracdata";

    //create connection
    $conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);
    if (mysqli_connect_error()) {
     die('Connect Error('. mysqli_connect_errno().')'. mysqli_connect_error());
    } else {
     $SELECT = "SELECT email From users Where email = ? Limit 1";
     $INSERT = "INSERT Into users (name, username, password, email, phone) values(?, ?, ?, ?)";

     //Prepare statement
     $stmt = $conn->prepare($SELECT);
     $stmt->bind_param("s", $email);
     $rnum = $stmt->num_rows;

     if ($rnum==0) {
      $stmt = $conn->prepare($INSERT);
      $stmt->bind_param("ssssii", $username, $username, $password, $email, $phone);

      echo "Your account has been registered!";
     } else {
      echo "This email is already linked to Preak account";
} else {
 echo "All fields are required";
How to&Answers: