Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known

39,745
mysqli_connect('root','', 'localhost', 'people');

You are passing root in as hostname.

try this

mysqli_connect('localhost','root', '', 'people');

this will connect to localhost with username root passwoord "" and default database people.

maybe better to change localhost with 127.0.0.1

Share:
39,745
Stelios Voskos
Author by

Stelios Voskos

Updated on July 07, 2022

Comments

  • Stelios Voskos
    Stelios Voskos almost 2 years

    I have just downloaded the wamp server. I want to establish a connection to MySQL database with PHP and I'm using the root user, localhost and the name of my database. My code seems to be correct but when I run it on wamp, I get the following error: Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\wamp\www\cone.php on line 8 and Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: No such host is known.

    Also, the error message that I haven't been connected to the database(from my if statement) is displayed.

    Does this mean that I have to do some extra configuration on the server?

    Here is my code:

    <?php

    $dbcon = mysqli_connect('root','', 'localhost', 'people');

    `if(!$dbcon)` 
    `{`
        `die('error connecting to database');`
    `}`
    `echo "success";`
    

    ?>

    Thank you in advance

    • KarelG
      KarelG almost 11 years
      is the wampserver service active in the background ?
    • Stelios Voskos
      Stelios Voskos almost 11 years
      Yes, I checked all the components of it and they are started
    • KarelG
      KarelG almost 11 years
      just noticed that the parameters isn't correct. Raymond's answer is the right one.
    • Gordon
      Gordon almost 11 years
      This question appears to be off-topic because it is about a typo (switched arguments)
    • Stelios Voskos
      Stelios Voskos almost 11 years
      It's from my first attempts to do that, so I'm sorry for the mess. Yeah, Raymond's answer was right, but now I have issue with this error:Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in C:\wamp\www\cone.php on line 3. This is relevant to my password on mysql I guess
  • Stelios Voskos
    Stelios Voskos almost 11 years
    Thanks! That took care of it. Now I get another error though: Warning: Warning: mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in C:\wamp\www\cone.php on line 3. Is this something relevant with my password on MySQL?
  • Mihai
    Mihai almost 11 years
    mysqli_connect('localhost','root', NULL, 'people');
  • Raymond Nijland
    Raymond Nijland almost 11 years
    Should be mysqli_connect('localhost','root', '', 'people');
  • Dhananjay
    Dhananjay over 10 years
    could you please tell location of this file?. I am using Drupal 7