0

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

Stelios Voskos
  • 17
  • 1
  • 1
  • 5
  • is the wampserver service active in the background ? – KarelG Aug 10 '13 at 12:17
  • Yes, I checked all the components of it and they are started – Stelios Voskos Aug 10 '13 at 12:18
  • just noticed that the parameters isn't correct. Raymond's answer is the right one. – KarelG Aug 10 '13 at 12:19
  • This question appears to be off-topic because it is about a typo (switched arguments) – Gordon Aug 10 '13 at 12:25
  • 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 Aug 10 '13 at 12:31

1 Answers1

3
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

Raymond Nijland
  • 11,488
  • 2
  • 22
  • 34