Jump to content

Database connection failed: ... No such host is known.


kimsbutt

Recommended Posts

( ! ) SCREAM: Error suppression ignored for

 

( ! ) Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\wamp\www\widget_corp\includes\connection.php on line 4

 

 

Database connection failed: php_network_getaddresses: getaddrinfo failed: No such host is known.

 

 

 

I am getting the error. I'm doing the PHP essential training course on Lynda.com. The teacher asked to make a constant.php file and then use constants to store the db user pass etc and then call it via the constant name or whatever and now i'm getting that huge error. I've been stuck for 2 days. Please help.

Link to comment
Share on other sites

should be a hint. You sure you have the right hostname?

Thanks for replying.

 

Yes, i was just trying random things, turns out it works if i use the actual host name, server, pass, and databasename but the instructor tells you to make a seprate php file which contains the info as such:

<?php

 

//Database Constants

define("SERVER", "localhost");

define("USER", "root");

define("PASS", "asdsfsadfsdfsd");

define("NAME", "widget_corp");

 

?>

 

and then on the content file link to it like so:

 

<?php

$connection = mysql_connect("SERVER","USER","PASS");

if(!$connection){

    die("Database connection failed: " . mysql_error());    

}

//2.Select a database to use

$db_select = mysql_select_db("NAME", $connection);

if(!$db_select){

    die("Database selection failed: " . mysql_error());    

}

?>

 

So I guess now my question is why doesn't constants work for me?

Link to comment
Share on other sites

You only need the quotes when you define the constant.

define("SERVER", "localhost");
Afterward, no quotes.

$connection = mysql_connect(SERVER, USER, PASS);
Otherwise PHP thinks you have a regular string and will happily use those as the values.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.