skip to Main Content

I was trying to make a simple database to write and read from and on pretty much one of the first steps I encountered a problem: it would not connect. I got the error message: "No connection could be made because the target machine actively refused it.". I looked at other stack overflow questions and they all had complex solutions involving changing the code of some things. I tried some, and nothing changed. I am using USBWebServer and phpMyAdmin. This is the index.php code that failed:

    $servername = "127.0.0.1";
    $username = "root";
    $password = "usbw";
    $databasetouse = "work times web database";
    // Create connection
    $mysqli = new mysqli($servername, $username, $password, $databasetouse);
    
    // Check connection
    if ($mysqli->connect_error) {
      die("Connection failed: " . $mysqli->connect_error);
    }
    echo "Connected successfully";

I tried changing $servername to "localhost" and nothing changed. When I first tried to log in to phpmyadmin it showed that my password was usbw and my username was root.

2

Answers


  1. I faced this error when I was learning laravel. Actually this happens when you database server is not being started.

    Login or Signup to reply.
  2. Maybe you should start your Apache and MySQL server through Xampp control panel and then try to connect.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search