Skip to content
Advertisement

Connection refused for connecting with MySQL server using php in XAMPP(MacOS)

I am new to database. I was trying to connect mysql server with php code. But I don’t know why I am getting error for connection.(I tried in windows changing the “localhost:8080” to “localhost” and it worked perfectly.)

MyCode:

<?php

$link = mysqli_connect("localhost:8080","root","","test1");

if($link === false){
    die("Error: Could not connect. ".mysqli_connect_error());
}

Refused Warning: enter image description here

XAMPP Port: enter image description here

Advertisement

Answer

localhost:8080 is for you web server. If your MySQL server runs on default settings, use port 3306. localhost:3306.

$link = mysqli_connect("localhost:3306","root","","test1");

Hope this helps you.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement