0

I'm kind of new to programming and I'm only trying to connect to database using xampp but it gives me this error.

Warning: mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it.

$conn = mysqli_connect('localhost', 'root', '', 'db');

I tried running the same code on a different PC and it works fine. so i guess the problem lies within PC that I'm working on. Any suggestions what to configure?

Sciryl
  • 55
  • 1
  • 8
  • 1
    your web server still sleep. wake him up!if you use linux do sudo /opt/lampp/lampp start. if you use windows just click start button – afikri Aug 26 '18 at 23:05
  • Thank you but MySQL is running but i'm still getting the error. – Sciryl Aug 26 '18 at 23:08
  • [duplicated see](https://stackoverflow.com/questions/21987746/mysql-connect-no-connection-could-be-made-because-the-target-machine-actively) – Bobby Axe Aug 26 '18 at 23:12
  • Did you create a password for mysql? – unixmiah Aug 26 '18 at 23:12
  • is this thread same as your problem?https://stackoverflow.com/questions/39810171/mysqli-connect-hy000-2002-no-connection-could-be-made-because-the-target-m – afikri Aug 26 '18 at 23:29
  • @BobbyAxe ok thank you for the link, i changed 'localhost' to '127.0.0.1' and it works.i'm sorry for the duplicate. – Sciryl Aug 26 '18 at 23:42

1 Answers1

0

If you are sure that login and password are all correct, then check port number. Default MySQL port is 3306. Maybe you've got different one on this machine. Or, it is also possible, default port in PHP may be changed.

See XAMPP configuration to see MySQL port and add it to your server address.

PS: you may also see privileges for "localhost" connection. See 'user' table in 'mysql' database. As you have XAMPP installed, you should have phpmyadmin as well.

Łukasz
  • 89
  • 8